Skip to content

Instantly share code, notes, and snippets.

@jimkang
Created January 3, 2014 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimkang/8242606 to your computer and use it in GitHub Desktop.
Save jimkang/8242606 to your computer and use it in GitHub Desktop.
Tacking forEach onto NodeList to reduce annoyance at it being different from [].
NodeList.prototype.forEach = function nodeListEach(callback, thisArg) {
for (var i = 0; i < this.length; ++i) {
var value = this[i];
if (thisArg) {
callback.bind(thisArg)(value, i, this);
}
else {
callback(value, i, this);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment