Skip to content

Instantly share code, notes, and snippets.

@dshaw
Created May 24, 2010 21:26
Show Gist options
  • Save dshaw/412448 to your computer and use it in GitHub Desktop.
Save dshaw/412448 to your computer and use it in GitHub Desktop.
Array.prototype.map
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/map
if (!Array.prototype.map)
{
Array.prototype.map = function(fun /*, thisp*/)
{
var len = this.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
res[i] = fun.call(thisp, this[i], i, this);
}
return res;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment