Vitaly Puzrin
10 years ago
4 changed files with 28 additions and 6 deletions
@ -0,0 +1,25 @@ |
|||
// Utilities
|
|||
'use strics'; |
|||
|
|||
|
|||
// Merge objects
|
|||
//
|
|||
exports.assign = function (obj /*from1, from2, from3, ...*/) { |
|||
var sources = Array.prototype.slice.call(arguments, 1); |
|||
while (sources.length) { |
|||
var source = sources.shift(); |
|||
if (!source) { continue; } |
|||
|
|||
if (typeof(source) !== 'object') { |
|||
throw new TypeError(source + 'must be non-object'); |
|||
} |
|||
|
|||
for (var p in source) { |
|||
if (source.hasOwnProperty(p)) { |
|||
obj[p] = source[p]; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return obj; |
|||
}; |
Loading…
Reference in new issue