question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prefer lodash functions over native JavaScript

See original GitHub issue

Now that we are introducing lodash (https://github.com/eslint/eslint/pull/5015) it would make sense to prefer lodash over the native JavaScript methods.

lodash has been created to provide a consistent cross-environment tested collection of utility functions to work with arrays, objects and strings. It is one of the most popular NPM packages.

Since ESLint goal is not related to dealing with cross-environment inconsistencies, it would make sense to abstract library code using a well-adapted utility library. Some benefits:

  • This would reduce the surface of the codebase.
  • This would reduce the testing scope.
  • This would make the code more consistent.
  • Using eslint-plugin-lodash enables to further enforce code consistency.
  • Using babel-plugin-lodash-modularize enables ES6 modularisation of the imports.
  • This would reduce the learning-gap needed to contribute to the codebase (user does not need to be aware of node version support for specific ES features).

@jdalton might have more arguments to add.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

15reactions
nzakascommented, Jan 20, 2016

👎 As I mentioned on the PR, I don’t like this approach. I want to use the native methods when available and only use lodash for things that aren’t available natively.

9reactions
jdaltoncommented, Jan 21, 2016

The only thing I’d add is that although lodash has methods like _.filter and _.map, which have ES5 flavors, it also has features, like iteratee shorthands to simplify code, that are missing from their ES5 counterparts.

_.map(objs, 'id');

instead of

objs.map(o=>(o!=null?o.id:void 0));

or

_.filter(objs, {'a':1,'b':{'c':2}});

instead of

objs.filter(o=>(o!=null&&o.a===1&&o.b!=null&&o.b.c===2));

In addition, methods like _.filter, _.map, _.slice, and others support lazy evaluation, shortcut fusion, when chaining without any additional work.

Once you start using lodash methods a bit more I’m sure places to cleanup ESLint will start to jump out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pure JavaScript Functions as a Replacement for Lodash | by RC
A brief overview of pure replacement functions over Lodash/Underscore.js. Functional Programming Illustrated. This post is a compilation of ...
Read more >
13 Lodash functions to replace with Pure JavaScript | DLT Labs
Here are 13 Lodash functions that can be replaced with Javascript functions: · 1> _.assignIn() · 2> _.values() · 3> _.pick() · 4>...
Read more >
Lodash's chain vs native methods | Blog - Maarten Hus
One killer feature of lodash is chains / sequences. Chains / sequences are lazy, in contrast with the native Array methods, which are...
Read more >
A Lodash Reference But With My Preferred Methods
Lodash takes several common operations in Javascript and makes them available in a functional programming form. The result is that code is ...
Read more >
Lodash vs JavaScript Built In for map,reduce,filter
Lodash is a nice tool to use if you have more complex algorithms, its more readable etc.. It has built in functions for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found