Created
December 27, 2015 15:33
-
-
Save hufyhang/c303ce1b80c7b6f8a73e to your computer and use it in GitHub Desktop.
JavaScript Array.prototype.forEach Polyfill
This file contains 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
/* | |
* 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