Created
May 26, 2013 02:05
-
-
Save jcblw/5651457 to your computer and use it in GitHub Desktop.
If I decide to add forEach to Marrow
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
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