Skip to content

Instantly share code, notes, and snippets.

@jcblw
Created May 26, 2013 02:05
Show Gist options
  • Save jcblw/5651457 to your computer and use it in GitHub Desktop.
Save jcblw/5651457 to your computer and use it in GitHub Desktop.
If I decide to add forEach to Marrow
Marrow.prototype.forEach = function(obj, fn){
if("forEach" in obj){
obj.forEach(fn); // native knows best
}else if("length" in obj){ // array
for(var i = 0; i < obj.length; i += 1){
fn(obj[i], i);
}
}else if(typeof obj === "object"){ // object
for(var key in obj){
fn(obj[key], key);
}
}else{
fn(null); // nothing
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment