Created
May 16, 2014 06:37
-
-
Save gfranko/b9f4d9e5773db83760cb to your computer and use it in GitHub Desktop.
.each() JavaScript implementation
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
function each (collection, callback) { | |
var x, len; | |
if(Utils.isArray(collection)) { | |
x = -1; | |
len = collection.length; | |
while(++x < len) { | |
if (callback(x, collection[x]) === false) { | |
break; | |
} | |
} | |
} else if(Utils.isPlainObject(collection)) { | |
for(x in collection) { | |
if(collection.hasOwnProperty(x)) { | |
if (callback(x, collection[x]) === false) { | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment