Created
October 18, 2011 06:35
-
-
Save josher19/1294754 to your computer and use it in GitHub Desktop.
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
/** | |
* Array.prototype.map Polyfill | |
*/ | |
Array.prototype.map = function(fun, thisp) { | |
"use strict"; | |
if (this === void 0 || this === null) { | |
throw new TypeError(); | |
} | |
var t = Object(this); | |
var len = t.length >>> 0; | |
if (typeof fun !== "function") { | |
throw new TypeError(); | |
} | |
var res = [ ]; | |
for (var i = 0; i < len; i++) { | |
if (i in t) { | |
var val = t[i]; // in case fun mutates this | |
res[i] = thisp ? fun.call(thisp, val, i, t) : fun(val, i, t); | |
} | |
} | |
return res; | |
}; | |
/* End of file map.js */ | |
/* | |
// add to polyfill.js : | |
// Array.prototype.map | |
map: { | |
test: function() { | |
return (!! Array.prototype.map); | |
} | |
}, | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment