Created
March 12, 2019 12:31
-
-
Save rkeVader/bea24b62f1a5ec5c45e276c08e732f90 to your computer and use it in GitHub Desktop.
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
if (Array.prototype.forEach != undefined) { | |
// Array->forEach exists... no polyfill necessary | |
console.log("Array->forEach exists. No PolyFill necessary!"); | |
} else { | |
// Array->forEach does not exist... polyfill necessary | |
console.log("Array->forEach does not exist. Resorting to PolyFill!"); | |
Array.prototype.forEach = function(callback, thisArg) { | |
if (typeof(callback) !== 'function') { | |
throw new TypeError(callback + ' is not a function!'); | |
} | |
var len = this.length; | |
for (var i = 0; i < len; i++) { | |
// callback goes here... | |
callback.call(thisArg, this[i], i, this); | |
} | |
} | |
} // Array->forEach should now exist one way or another... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment