Jump to content

Underscore.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by J+ (talk | contribs) at 04:22, 1 March 2021 (Introduction: It is no longer true that _.each defers to builtin Array.forEach). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Developer(s)Jeremy Ashkenas
Initial releaseOctober 28, 2009; 15 years ago (2009-10-28)[1]
Stable release
1.12.0 / November 24, 2020; 4 years ago (2020-11-24)
Repository
Written inJavaScript
Size7.4 KB production
67 KB development
TypeJavaScript library
LicenseMIT
Websiteunderscorejs.org

Underscore.js is a JavaScript library which provides utility functions for common programming tasks.[2] It is comparable to features provided by Prototype.js and the Ruby language, but opts for a functional programming design instead of extending object prototypes. The documentation refers to Underscore.js as "the tie to go along with jQuery's tux, and Backbone.js' suspenders." Underscore.js was created by Jeremy Ashkenas, who is also known for Backbone.js and CoffeeScript.[3]

History

Jeremy Ashkenas created Underscore by the end of 2009 as a spin-off from the DocumentCloud project, together with Backbone.js. It was one of the earliest libraries for JavaScript to provide general functional programming utilities, taking inspiration from Prototype.js, Oliver Steele's Functional JavaScript, and John Resig's Micro-Templating.[4]

In 2012, John-David Dalton created a fork of Underscore, named Lo-Dash (now Lodash). Lo-Dash was initially promoted as a drop-in alternative for Underscore with "consistency, customization, performance, & extras".[5] Nevertheless, Lodash already departed from the original Underscore interface at an early stage[6] and started making more drastic changes with the 3.0.0 release, making it necessary for Lodash users to change their code.[7]

In May 2015, Jeremy Ashkenas announced that John-David Dalton had contacted him about merging the libraries back together. Despite concerns about code style and code size, Ashkenas was not opposed to merging some of Lodash's extensions into Underscore.[8] At the time, there were several developers contributing to Underscore and Lodash in parallel; this group of contributors started making changes to Underscore in order to make it more like Lodash.[9]

In parallel to this effort, however, Dalton made more drastic changes to the Lodash interface. In June 2015, he announced Lodash version 4.0.0, which distanced Lodash even further from the Underscore interface, while making a significant departure from the version 3.x series of Lodash itself as well.[10][11] This prompted some projects that depended on Lodash to create their own distributions of Lodash 3.[12]

In February 2016, Dalton announced that he considered the merge effort to be complete. He suggested that users switch from Underscore to Lodash, motivating this with usage share statistics.[13] A maintainer of Underscore however made clear that there was no intention to stop developing Underscore as a separate library.[14] Both libraries entered a state of low development activity after 2016.[15][16]

Over time, newer versions of the ECMAScript standard have added builtin functions to the language that replicate some of the functionality of Underscore, such as Object.assign and Array.prototype.map. This has sometimes led to the perception that Underscore no longer adds value to a JavaScript project.[17] The builtin functions are however less powerful than their Underscore equivalents; in particular, builtin array iteration methods such as map, filter and forEach cannot iterate over plain objects and do not support iteratee shorthands.[18][19][20][21][22][23] Besides this, most of Underscore's functions still have no builtin counterpart at all.[24][25]

As of March 2021, Underscore is being actively developed by Julian Gonggrijp, who started making major contributions in March 2020.[15] The library is still widely depended upon and is being downloaded from npm several million times every week.[26]

Content

Underscore consists of a little more than 100 functions, which fall under four main categories depending on the datatypes which they manipulate: functions for manipulating arrays, functions for manipulating objects, functions for manipulating both arrays and objects (the name of the category is "Collections") and functions for manipulating other functions. There are also two utility categories: "Utility" and "Chaining".[citation needed]

See also

References

  1. ^ Release 0.1.0, jashkenas/underscore, GitHub
  2. ^ "Underscore.js – ein kleines Framework mit Fokus". entwickler.de (in German). 20 June 2018. Retrieved 9 July 2020.
  3. ^ "JavaScript Meetup City", Open, The New York Times, April 4, 2012
  4. ^ Ashkenas, Jeremy. "Underscore 0.4.0 source". cdn.rawgit.com. Retrieved 1 March 2021.
  5. ^ "Lo-Dash v2.2.1". lodash.com. Archived from the original on 6 November 2013. Retrieved 1 March 2021.
  6. ^ "Lodash Changelog - 1.0.0 rc1". github.com. 4 December 2012. Retrieved 1 March 2021.
  7. ^ "Lodash Changelog - 3.0.0". github.com. 26 January 2015. Retrieved 1 March 2021.
  8. ^ Ashkenas, Jeremy (21 May 2015). "The Big Kahuna: Underscore + Lodash Merge Thread". github.com. Retrieved 1 March 2021.
  9. ^ "Underscore: merged pull requests with breaking changes between 21 May and 1 October 2015". github.com. Retrieved 1 March 2021.
  10. ^ Dalton, John-David (8 June 2015). "comment on 'Core API'". github.com. Retrieved 1 March 2021.
  11. ^ "Lodash changelog 4.0.0". github.com. 12 January 2016. Retrieved 1 March 2021.
  12. ^ "@sailshq/lodash". npmjs.com. Retrieved 1 March 2021.
  13. ^ Dalton, John-David (13 February 2016). "Merge update". github.com. Retrieved 1 March 2021.
  14. ^ Krebs, Adam (17 February 2016). "comment on 'Merge update.'". github.com. Retrieved 1 March 2021.
  15. ^ a b "jashkenas/underscore Insights: Contributors". github.com. Retrieved 1 March 2021.
  16. ^ "lodash/lodash Insight: Contributors". github.com. Retrieved 1 March 2021.
  17. ^ lorduhr (5 September 2020). "comment on 'Underscore went modular: version 1.11 released'". reddit.com. Retrieved 1 March 2021.
  18. ^ "Array.prototype.map". developer.mozilla.org. Retrieved 1 March 2021.
  19. ^ "Array.prototype.filter". developer.mozilla.org. Retrieved 1 March 2021.
  20. ^ "Array.prototype.forEach". developer.mozilla.org. Retrieved 1 March 2021.
  21. ^ "_.map". underscorejs.org. Retrieved 1 March 2021.
  22. ^ "_.filter". underscorejs.org. Retrieved 1 March 2021.
  23. ^ "_.each". underscorejs.org. Retrieved 1 March 2021.
  24. ^ "Underscore.js". underscorejs.org. Retrieved 1 March 2021.
  25. ^ "JavaScript reference". developer.mozilla.org. Retrieved 1 March 2021.
  26. ^ "underscore". npmjs.com. Retrieved 1 March 2021.