Skip to content

Instantly share code, notes, and snippets.

@jasondmoss
Created December 10, 2019 03:44
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 jasondmoss/a7057eeaa33f70959429c33bd3dba2b6 to your computer and use it in GitHub Desktop.
Save jasondmoss/a7057eeaa33f70959429c33bd3dba2b6 to your computer and use it in GitHub Desktop.
Polyfill Methods for Internet Explorer 11 and below.
/**
* Polofill for `Array​.prototype​.for​Each()`
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
*/
if (!Array.prototype.forEach) {
Array.prototype.forEach = function (callback/*, thisArg*/) {
"use strict";
var T, k;
if (this == null) {
throw new TypeError("this is null or not defined");
}
var O = Object(this);
var len = O.length >>> 0;
/**
* If isCallable(callback) is false, throw a TypeError exception.
*
* @see http://es5.github.com/#x9.11
*/
if (typeof callback !== "function") {
throw new TypeError(callback +" is not a function");
}
if (arguments.length > 1) {
T = arguments[1];
}
k = 0;
while (k < len) {
var kValue;
if (k in O) {
kValue = O[k];
/**
* Call the Call internal method of callback with T as the this
* value and argument list containing kValue, k, and O.
*/
callback.call(T, kValue, k, O);
}
k++;
}
};
}
/* <> */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment