Skip to content

Instantly share code, notes, and snippets.

@chambaz
Created February 8, 2014 23:39
Show Gist options
  • Save chambaz/8892052 to your computer and use it in GitHub Desktop.
Save chambaz/8892052 to your computer and use it in GitHub Desktop.
Array.forEach Polyfill
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisArg */)
{
"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 thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++)
{
if (i in t)
fun.call(thisArg, t[i], i, t);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment