Skip to content

Commit

Permalink
fix(object): assign ignores null or undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Mar 8, 2016
1 parent d335a8f commit 941a892
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions src/object.js
Expand Up @@ -54,27 +54,25 @@
}());

(function (O) {
if ('assign' in O) return;
O.defineProperty(
O,
'assign',
{
if ('assign' in O) {
return;
}

O.defineProperty(O, 'assign', {
configurable: true,
writable: true,
value: (function () {
var
gOPS = O.getOwnPropertySymbols,
// shortcut without explicitly passing through prototype
pIE = O.propertyIsEnumerable,
filterOS = gOPS ?
function (self) {
return gOPS(self).filter(pIE, self);
} :
function () {
// just empty Array won't do much within a .concat(...)
return Array.prototype;
}
;
value: (function() {
var gOPS = O.getOwnPropertySymbols,
// shortcut without explicitly passing through prototype
pIE = O.propertyIsEnumerable,
filterOS = gOPS ?
function (self) {
return gOPS(self).filter(pIE, self);
} : function () {
// just empty Array won't do much within a .concat(...)
return Array.prototype;
};

return function assign(where) {
// Object.create(null) and null objects in general
// might not be fully compatible with Symbols libraries
Expand All @@ -83,27 +81,25 @@
// if you know what you are doing ... so ....
if (gOPS && !(where instanceof O)) {
console.warn('problematic Symbols', where);
// ... now this script does its bloody business !!!
// ... now this script does its business !!!
}
// avoid JSHint "don't make function in loop"
function set(keyOrSymbol) {
where[keyOrSymbol] = arg[keyOrSymbol];
}
// the loop
for (var
arg,
i = 1; i < arguments.length; i++
) {
arg = arguments[i];
O
.keys(arg)
.concat(filterOS(arg))
.forEach(set)
;
for (var i = 1, ii = arguments.length; i < ii; ++i) {
var arg = arguments[i];

if (arg === null || arg === undefined) {
continue;
}

O.keys(arg).concat(filterOS(arg)).forEach(set);
}

return where;
};
}())
}
);
});
}(Object));

0 comments on commit 941a892

Please sign in to comment.