Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the name 'underscore' or 'lodash'?

Why are these libraries named after _ ?

Is there some significance behind it or the reason is "Just because we can"?

As far as i know, underscore and lodash do a lot of similar stuff. Also, both the names point to _

Even their variable names are _

So is there some relation of _ with the working of these libraries? Or its just a name?

like image 955
Dushyant Bangal Avatar asked Jun 24 '16 05:06

Dushyant Bangal


Video Answer


1 Answers

Lodash

From my understanding of the history of the two, lodash was meant as a lightweight replacement for underscore. So lodash is effectively a play on words on underscore - "low dash", what does a dash - look like when its a bit lower to the ground? _ Why, an underscore of course

So that covers lodash in as much detail as it warrants.

Underscore

Underscore's origin would only be a guess - but a guess I shall make.

"Back in the golden days" of Javascript, when the mighty JQuery reigned supreme, small (at the time) utility libraries started emerging - but one thing we didn't have at the time (or wasn't well known) was simple constructs for import and requiring external libraries.

Very much like JQuery grouping all of its functionality under one giant $ object - underscore (I am guessing) wanted the same. Why? Probably for brevity and that l33t factor. Especially in the days where most people were just including a bunch of script tags in the footer. If you were looking at utility library home page, what appeals to you more:

// totes l33t
_.map(a, function(e) { ... }

// pfft, no thanks grandpa
underscore.map(a, function(e) { ... }

But why _. Well after $ its one of few cool short names left:

An identifier must start with $, _, or any character in the Unicode categories “Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number (Nl)”.

https://mathiasbynens.be/notes/javascript-identifiers

like image 158
Chris Avatar answered Sep 22 '22 19:09

Chris