Skip to content

Instantly share code, notes, and snippets.

@chrisjhoughton
Created December 10, 2013 13:04
Show Gist options
  • Select an option

  • Save chrisjhoughton/7890274 to your computer and use it in GitHub Desktop.

Select an option

Save chrisjhoughton/7890274 to your computer and use it in GitHub Desktop.
Foreach from MoutJS. Never write a for loop again!
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