Skip to content

Instantly share code, notes, and snippets.

@jwulf
Created March 4, 2020 15:31
Show Gist options
  • Save jwulf/05a31e21fa38937508bf17a39c1476d9 to your computer and use it in GitHub Desktop.
Save jwulf/05a31e21fa38937508bf17a39c1476d9 to your computer and use it in GitHub Desktop.
// Production steps of ECMA-262, Edition 5, 15.4.4.19
// Reference: http://es5.github.io/#x15.4.4.19
if (!Array.prototype.map) {
Array.prototype.map = function(callback/*, thisArg*/) {
var T, A, k;
if (this == null) {
throw new TypeError('this is null or not defined');
}
var O = Object(this);
var len = O.length >>> 0;
if (typeof callback !== 'function') {
throw new TypeError(callback + ' is not a function');
}
if (arguments.length > 1) {
T = arguments[1];
}
A = new Array(len);
k = 0;
while (k < len) {
var kValue, mappedValue;
if (k in O) {
kValue = O[k];
mappedValue = callback.call(T, kValue, k, O);
A[k] = mappedValue;
}
k++;
}
return A;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment