Skip to content

Instantly share code, notes, and snippets.

@asedmammad
Created July 30, 2022 11:25
Show Gist options
  • Save asedmammad/7d44188ca849ee5872be004e4b0c0810 to your computer and use it in GitHub Desktop.
Save asedmammad/7d44188ca849ee5872be004e4b0c0810 to your computer and use it in GitHub Desktop.
Object assign polyfill
if (!Object.assign) {
Object.assign = function assign(target, source) {
'use strict';
if (target === undefined || target === null) {
throw new TypeError('Cannot convert first argument to object');
}
var to = Object(target);
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i];
if (nextSource === undefined || nextSource === null) {
continue;
}
nextSource = Object(nextSource);
var keysArray = Object.keys(Object(nextSource));
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc !== undefined && desc.enumerable) {
to[nextKey] = nextSource[nextKey];
}
}
}
return to;
};
Object.defineProperty(Object, 'assign', {enumerable: false, configurable: true, writable: true});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment