Skip to content

Instantly share code, notes, and snippets.

@estebistec
Created May 23, 2014 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save estebistec/a9e24e45e3d2362e8c9a to your computer and use it in GitHub Desktop.
Save estebistec/a9e24e45e3d2362e8c9a to your computer and use it in GitHub Desktop.
JavaScript polyfills
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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