Created
January 27, 2016 00:32
-
-
Save divmain/c93a0d1854bfe1ff1616 to your computer and use it in GitHub Desktop.
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
if (typeof Object.assign != 'function') { | |
(function () { | |
Object.assign = function (target) { | |
'use strict'; | |
if (target === undefined || target === null) { | |
throw new TypeError('Cannot convert undefined or null to object'); | |
} | |
var output = Object(target); | |
for (var index = 1; index < arguments.length; index++) { | |
var source = arguments[index]; | |
if (source !== undefined && source !== null) { | |
for (var nextKey in source) { | |
if (source.hasOwnProperty(nextKey)) { | |
output[nextKey] = source[nextKey]; | |
} | |
} | |
} | |
} | |
return output; | |
}; | |
})(); | |
} | |
if (!Array.prototype.fill) { | |
Array.prototype.fill = function(value) { | |
// Steps 1-2. | |
if (this == null) { | |
throw new TypeError('this is null or not defined'); | |
} | |
var O = Object(this); | |
// Steps 3-5. | |
var len = O.length >>> 0; | |
// Steps 6-7. | |
var start = arguments[1]; | |
var relativeStart = start >> 0; | |
// Step 8. | |
var k = relativeStart < 0 ? | |
Math.max(len + relativeStart, 0) : | |
Math.min(relativeStart, len); | |
// Steps 9-10. | |
var end = arguments[2]; | |
var relativeEnd = end === undefined ? | |
len : end >> 0; | |
// Step 11. | |
var final = relativeEnd < 0 ? | |
Math.max(len + relativeEnd, 0) : | |
Math.min(relativeEnd, len); | |
// Step 12. | |
while (k < final) { | |
O[k] = value; | |
k++; | |
} | |
// Step 13. | |
return O; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment