Last active
April 5, 2017 08:29
-
-
Save icetee/fae755b7ce8f90d9d7bc8a7ece2cf3cb to your computer and use it in GitHub Desktop.
Add support Object.assign old browsers. Source: http://codepen.io/souporserious/pen/Boavdv
This file contains 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
/* Add suspport assign method (> IE9) | |
* https://gist.github.com/icetee/fae755b7ce8f90d9d7bc8a7ece2cf3cb | |
*/ | |
if (!Object.assign && Object.hasOwnProperty('defineProperty')) { | |
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(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; | |
} | |
}); | |
} |
This file contains 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
/* Add suspport assign method (> IE9) | |
* https://gist.github.com/icetee/fae755b7ce8f90d9d7bc8a7ece2cf3cb | |
*/ | |
if(!Object.assign&&Object.hasOwnProperty("defineProperty")){Object.defineProperty(Object,"assign",{enumerable:false,configurable:true,writable:true,value:function(g){if(g===undefined||g===null){throw new TypeError("Cannot convert first argument to object")}var j=Object(g);for(var a=1;a<arguments.length;a++){var d=arguments[a];if(d===undefined||d===null){continue}d=Object(d);var b=Object.keys(Object(d));for(var c=0,f=b.length;c<f;c++){var h=b[c];var e=Object.getOwnPropertyDescriptor(d,h);if(e!==undefined&&e.enumerable){j[h]=d[h]}}}return j}})}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment