Created
March 17, 2014 22:24
-
-
Save onestepcreative/9609638 to your computer and use it in GitHub Desktop.
for each loop helper from hammer.js
This file contains hidden or 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
| var Obj = { | |
| each: function(obj, iterator, context) { | |
| var i, o; | |
| // native forEach on arrays | |
| if ('forEach' in obj) { | |
| obj.forEach(iterator, context); | |
| } | |
| // arrays | |
| else if(obj.length !== undefined) { | |
| for(i=-1; (o=obj[++i]);) { | |
| if (iterator.call(context, o, i, obj) === false) { | |
| return; | |
| } | |
| } | |
| } | |
| // objects | |
| else { | |
| for(i in obj) { | |
| if(obj.hasOwnProperty(i) && | |
| iterator.call(context, obj[i], i, obj) === false) { | |
| return; | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment