Created
October 12, 2021 13:21
-
-
Save bgreenacre/f00ad4afed12a04715008558f57eea87 to your computer and use it in GitHub Desktop.
polyfill for object.assign
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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(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; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment