3 ms·
_.filter is NOT equivalent to Array.prototype.filter. The array could be null/undefined, in which case the _.filter just works fine, but Array.protoype.filter
by mduerksen 10y ago
_.filter is NOT equivalent to Array.prototype.filter.
The array could be null/undefined, in which case the _.filter just works fine, but Array.protoype.filter does not.
I hate to riddle my code with null checks I actually do not care about.
- eknkc 10y ago(arr || []).filter... Is something I do when I'm not sure if the array is null or not. Looks shitty but works fine. (Now if arr is not falsy and not an array either, this blows up. But I don't know what lodash does then too) To be honest, I'd rather check / handle nulls rather than to rely on an external library semantics. They might also change it tomorrow and upgrading would be a pain.
- jdd 10y agoThe language changes too. In ES5 `Object.keys` throws an error for `Object.keys('abc')` but in ES6 it returns an array.