Created
February 4, 2011 22:24
-
-
Save bmavity/811895 to your computer and use it in GitHub Desktop.
Object iteration
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
// Implementation | |
var iter = function(obj, callback) { | |
Object.keys(obj).forEach(function(key) { | |
callback(key, obj[key]); | |
}); | |
}; | |
// Usage | |
iter(obj, function(name, val) { | |
// Do shit here | |
}); | |
// Even better | |
obj.iter(function(name, val) { | |
// Do shit here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment