You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
prefer-lodash-method is included in the lodash/recommended rule set. The docs for that rule just say:
When using native functions like forEach and map, it's often better to use the Lodash implementation.
It would be helpful if this page mentioned the reasons it's "often better" to use the lodash methods. I'm thinking about disabling this warning, but I'd like to know the pros/cons.
The text was updated successfully, but these errors were encountered:
Performance reasons: Lodash methods tend to be quite a bit faster than native ones.
It "crashes" less: In the sense that array.map(fn) would crash when array is null, Lodash's methods do not (map returns empty array, forEach does nothing for instance)
You can use shorthands that make quite a few iteratees/predicates shorter to write:
constrefs=array.map(function(value){returnvalue.ref;});constrefs=array.map(value=>value.ref);// Shorter arrow notation// vsconstrefs=_.map(array,'ref');// again, if there are `undefined` values in array, this won't crash eitherconstbigApple=fruits.find(function(fruit){// Array.prototype.find exists in ES6returnfruit.type==='apple'&&fruit.size==='big';});constbigApple=fruits.find(fruit=>fruit.type==='apple'&&fruit.size==='big');// Shorter arrow notation// vsconstbigApple=_.find(fruits,{type: 'apple',size: 'big'});
prefer-lodash-method
is included in thelodash/recommended
rule set. The docs for that rule just say:It would be helpful if this page mentioned the reasons it's "often better" to use the lodash methods. I'm thinking about disabling this warning, but I'd like to know the pros/cons.
The text was updated successfully, but these errors were encountered: