3 ms·
If I'm understanding get() correctly here, why not just use: var totals = orders.map(get("total")); Why needlessly use specialized jargon when common term
by AnIrishDuck 14y ago
If I'm understanding get() correctly here, why not just use:
var totals = orders.map(get("total"));
Why needlessly use specialized jargon when common terms work just fine?
- raganwald 14y agoThat's fine, as is _.map(orders, get('total')) or just plain map(orders, get('total')). As I explained in another comment, splat is a combinator, which makes it particularly easy to compose. Compare: function pluck (list, propertyName) { return _.map(list, get(propertyName)); }; to: var pluck = compose(splat, get); So yes, for that one line you should use map, but when making things out of the mapping construct, it is sometimes handy to use splat. Other folks have introduced the idea that splat is really nothing more than flip(curry(map)). There's a good argument for better naming once you realize the underlying symmetry.