function extend(target, deep, source /*, source, ... */) {
/// <summary>Copies the properties of one or more objects to target.</summary>
/// <param name="target" type="Object">The object upon which to copy the properties of source object(s)</param>
/// <param name="deep" type="Boolean">If true, deep copy using recursion.</param>
/// <param name="source" type="Object">Multiple source objects are supported.</param>
var source;
for (var argIndex = 2, argCount = arguments.length; argIndex < argCount; argIndex++)
if ((source = arguments[argIndex]) != null) {
for (var key in source) {
if (target == source[key]) {
// prevent stackoverflow due to recursion
continue;
}
if (deep && typeof source[key] == 'object' && target[i]) {
extend(target[key], source[key]);
}
else if (source[key] != undefined) {
target[key] = source[key];
}
}
}
return target;
}
Technorati tags:
JavaScript