Skip to content

Instantly share code, notes, and snippets.

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