4 ms·
Maybe it's just me but this strikes me as a great argument for leaving it like it is: callbacks.forEach(function(callback) { callback(); }); Eve
by serve_yay 12y ago
Maybe it's just me but this strikes me as a great argument for leaving it like it is:
callbacks.forEach(function(callback) {
callback();
});
Everybody knows what it does. Simple.
- grimtrigger 12y agoI think the author comes to that conclusion, the article is just a thought experiment
- serve_yay 12y agoSure, I'm just making the point that sometimes when you look at something like that and think it can be improved, it's worth considering that the cure may end up being worse than the disease.
- zpao 12y agoIt is worth considering, but it's often worth finding out what the cure is before writing it off. You have to make the right tradeoffs (eg, when working on a tight deadline, it's probably not the right call to go off into the weeds finding out if you can make 3 lines of code into 1).
- baddox 12y agoSometimes, yes. And sometimes not. If, for instance, the author would have discovered that forEach worked differently, and there was some function that JS provides that worked cleanly with a readable name, then the article could have concluded that it makes sense to use that.
- brbcoding 12y agoIt also seems to be a bit more performant than some of the other methods (like `.shift()()` or `.call`). http://jsfiddle.net/brbcoding/hyw6a9kw/3/ http://jsfiddle.net/brbcoding/hyw6a9kw/3/