4 ms·
You're saving at least two characters there ;) I think sensible semantic naming still helps in this circumstance. yummyBars = candyBars.filter(function(ba
by knowtheory 14y ago
You're saving at least two characters there ;)
I think sensible semantic naming still helps in this circumstance.
yummyBars = candyBars.filter(function(bar){ return bar.yummy; });
makes it clearer that the thing you're getting back is like the thing you had previously.
One place this could be useful is in Backbone.Collection where the array-returning mixins from underscore all hand back bare arrays, on which devs must then switch to _ prefixed functions (although you're right that this does keep a clear conceptual separation between collections and other arrays).
- javajosh 14y agoI get a warm and fuzzy when I know what that method does, that it's not some random filter that could mean something totally different. (And yes, this does mean that my code is not very object oriented at all!)
- knowtheory 14y agoThat's okay! Use the right tool in the right place. And agreed, I like knowing where a function comes from. I'm not totally convinced by the move to 100% functionalist constructs (there are some places where OO is nice), but it's a nice stylistic practice.