Skip to content

Instantly share code, notes, and snippets.

@cheeaun
Created October 27, 2009 07:11
Show Gist options
  • Save cheeaun/219390 to your computer and use it in GitHub Desktop.
Save cheeaun/219390 to your computer and use it in GitHub Desktop.
Array.each which allows 'return false' to break the loop.
// Array native is protected, so can't do Array.implement
Array.prototype.each = function(fn, bind){
for (var i = 0, l = this.length; i < l; i++){
var r = fn.call(bind, this[i], i, this);
if (r === false) break;
}
};
Native.genericize(Array, 'each', true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment