JavaScript Array.prototype.forEach Polyfill
/* | |
* forEach Polyfill | |
* | |
* 2015-12-27 | |
* | |
* By Feifei Hang, http://feifeihang.info | |
* Public Domain. | |
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
*/ | |
'use strict'; | |
(function () { | |
if (!Array.prototype.forEach) { | |
Array.prototype.forEach = function forEach (callback, thisArg) { | |
if (typeof callback !== 'function') { | |
throw new TypeError(callback + ' is not a function'); | |
} | |
var array = this; | |
thisArg = thisArg || this; | |
for (var i = 0, l = array.length; i !== l; ++i) { | |
callback.call(thisArg, array[i], i, array); | |
} | |
}; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment