Skip to content

Instantly share code, notes, and snippets.

@tj
Created December 13, 2009 21:16
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 tj/255605 to your computer and use it in GitHub Desktop.
Save tj/255605 to your computer and use it in GitHub Desktop.
/**
* Iterate collection using callback _fn_,
* passing both the value and index.
*
* @param {function} fn
* @return {Collection}
* @api public
*/
each: function(fn) {
try {
if (this.arr.forEach) {
this.arr.forEach(fn)
} else {
for (var key in this.arr) {
if (this.arr.hasOwnProperty(key)) {
fn(this.arr[key], key)
}
}
}
catch (e) {
if (e != $break) throw e
}
return this
}
/**
* Iterate collection using callback _fn_,
* passing both the value and index.
*
* @param {function} fn
* @return {Collection}
* @api public
*/
each: function(fn) {
try {
if (this.arr.forEach)
this.arr.forEach(fn)
else
for (var key in this.arr)
if (this.arr.hasOwnProperty(key))
fn(this.arr[key], key)
}
catch (e) {
if (e != $break) throw e
}
return this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment