Skip to content

Instantly share code, notes, and snippets.

@zziuni
Created Aug 9, 2012
Embed
What would you like to do?
Array.forEach and NodeList.forEach Compatibility
if ( !Array.prototype.forEach ) {
Array.prototype.forEach = function(fn, scope) {
for(var i = 0, len = this.length; i < len; ++i) {
fn.call(scope || this, this[i], i, this);
}
}
}
if ( !NodeList.prototype.forEach ) {
NodeList.prototype.forEach = function(fn, scope) {
for(var i = 0, len = this.length; i < len; ++i) {
fn.call(scope || this, this[i], i, this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment