Created
October 27, 2009 07:11
-
-
Save cheeaun/219390 to your computer and use it in GitHub Desktop.
Array.each which allows 'return false' to break the loop.
This file contains hidden or 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
// 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