Why the name 'underscore' or 'lodash'?

喜你入骨 提交于 2019-12-11 00:27:08

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/38006384/why-the-name-underscore-or-lodash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!