Wednesday, July 17, 2019

Why I use Vanilla (Native) Javascript, not Underscore.js or Lodash?

Underscore.js and Lodash are javascript utility library written using functional programming. Lodash is the level up version from Underscore.js.  Most of its ideas and contributors are from Underscore.js. Both libraries used to be my favourite until ECMA 2016 where developers can code ECMA 2016 without using Underscore.js and Lodash. Here are a few examples:

const users = [
  { 'user': 'joey',  'age': 32 },
  { 'user': 'ross',    'age': 41 },
  { 'user': 'chandler', 'age': 39 }
]

// Native
users.find(function (o) { return o.age < 40; })

//lodash
_.find(users, function (o) { return o.age < 40; })

// Native
users.filter(function (o) { return o.age < 40; })

//lodash
_.filter(users, function (o) { return o.age < 40; })

// Native
users[0]

//lodash
_.first(users)

// Native
users.forEach((value, index) => { console.log(value) })

//lodash
_.each(users, (value, index) => { console.log(value) })
I am not here to against Underscore.js or Ladash. Whatever the decision, think about future maintenance and support, and speed.

Underscore.js and Ladash maintenance by public and no promise on the future roadmap. Vanilla javascript maintenances by various organizations involved Mozilla, Google, Microsoft, etc. Every year has a new release since the year 2015, the current version is ECMA 2019.

In term of speed, some methods in Ladash are faster than vanilla javascript because of functional programming.

https://underscorejs.org/
https://lodash.com/
https://en.wikipedia.org/wiki/ECMAScript
https://codeburst.io/why-you-shouldnt-use-lodash-anymore-and-use-pure-javascript-instead-c397df51a66
https://blog.bitsrc.io/you-dont-need-lodash-or-how-i-started-loving-javascript-functions-3f45791fa6cd

No comments:

Post a Comment