Created
December 10, 2019 03:44
-
-
Save jasondmoss/a7057eeaa33f70959429c33bd3dba2b6 to your computer and use it in GitHub Desktop.
Polyfill Methods for Internet Explorer 11 and below.
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
/** | |
* Polofill for `Array.prototype.forEach()` | |
* | |
* @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