Created
December 10, 2013 13:04
-
-
Save chrisjhoughton/7890274 to your computer and use it in GitHub Desktop.
Foreach from MoutJS. Never write a for loop again!
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
| var forEach = function(arr, callback, thisObj) { | |
| if (arr === null) { | |
| return; | |
| } | |
| var i = -1, | |
| len = arr.length; | |
| while (++i < len) { | |
| // we iterate over sparse items since there is no way to make it | |
| // work properly on IE 7-8. see #64 | |
| if (callback.call(thisObj, arr[i], i, arr) === false) { | |
| break; | |
| } | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment