Skip to content

Instantly share code, notes, and snippets.

@osiyuk
Forked from spiralx/object-assign.js
Last active November 13, 2016 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osiyuk/c13b6c9a9fd1acdc87570118355aaf98 to your computer and use it in GitHub Desktop.
Save osiyuk/c13b6c9a9fd1acdc87570118355aaf98 to your computer and use it in GitHub Desktop.
Object.assign() polyfill
if (!Object.assign) {
Object.defineProperty(Object, 'assign', {
enumerable: false,
configurable: true,
writable: true,
value: function (target) {
'use strict';
if (target === undefined || target === null) {
throw new TypeError('Cannot convert first argument to object');
}
var next, keys, len, key, desc, i, j;
target = Object(target);
for (i = 1; i < arguments.length; i++) {
next = arguments[i];
if (next === undefined || next === null) {
continue;
}
next = Object(next);
keys = Object.keys(next);
for (j = 0, len = keys.length; j < len; j++) {
key = keys[j];
desc = Object.getOwnPropertyDescriptor(next, key);
if (desc !== undefined && desc.enumerable)
target[key] = next[key];
}
}
return target;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment