3 ms·
"...or you can write it in CS with a for loop which cleans up the syntax quite a bit" For each loops are great, but there is certainly value in having $.each b
by tolmasky 14y ago
"...or you can write it in CS with a for loop which cleans up the syntax quite a bit"
For each loops are great, but there is certainly value in having $.each be a function as well as a statement. For example, if you want to pass it to another function in more functional style programming: do_something($.each);
"or it might be possible to reduce your input first so that you are only iterating over the things you actually want to iterate over..."
It seems you don't understand the point of returning false from $.each, it is not to filter, it is to stop early. For example, if you are doing a linear search for something, it is reasonable to want to stop after you find it. There is no way to "iterate over the things you actually want to iterate over".
- latchkey 14y agoI think you're stretching here. Passing $.each to a function makes no sense when it is effectively a global anyway. Please give me a real world example of why you would do something like that (not in the functional aspect, that I understand... I am talking specifically about $.each). I also wouldn't use something called $.each to do a linear search. I'd use underscore.js _.find(), which has a sane api, you return true when you want to stop. This thing I'm looking for has been found. Array.forEach and _.each() chose not to support returning false. I can only assume that is @jashkenas being wise.