Fixup copyInto function

* Drop any undefined values
* Copy non-objects, too
1.3
execjosh 2011-08-28 23:12:52 +09:00
parent 74db4807d5
commit da97b9abbf
1 changed files with 11 additions and 6 deletions

View File

@ -24,18 +24,19 @@ window.WebPage = function (opts) {
}
function copyInto(target, source) {
if (isUndefinedOrNull(target)) {
return (isUndefinedOrNull(source)) ? target : source;
if (target === source || isUndefinedOrNull(source)) {
return target;
}
var i, newTarget, newSource;
target = target || {};
// Copy into objects only
if (target !== source && isObject(target)) {
if (isObject(target)) {
// Make sure source exists
source = source || false;
source = source || {};
if (isObject(source)) {
var i, newTarget, newSource;
for (i in source) {
if (source.hasOwnProperty(i)) {
newTarget = target[i];
@ -48,9 +49,13 @@ window.WebPage = function (opts) {
newTarget = newSource;
}
target[i] = newTarget;
if (!isUndefined(newTarget)) {
target[i] = newTarget;
}
}
}
} else {
target = source;
}
}