Created
May 23, 2014 23:09
-
-
Save estebistec/a9e24e45e3d2362e8c9a to your computer and use it in GitHub Desktop.
JavaScript polyfills
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
// 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