Created
December 13, 2009 21:16
-
-
Save tj/255605 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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 | |
} |
This file contains 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
/** | |
* 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