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