Why did Underscore.js remove support for AMD?

Javascriptunderscore.jsRequirejsJs Amd

Javascript Problem Overview


> 1.3.0 — Jan. 11, 2012 Removed AMD (RequireJS) support from Underscore. If you'd like to use Underscore with RequireJS, you can load it as a normal script, wrap or patch your copy, or download a forked version.

Why have they done it? Does anyone know? Because they added it only few month ago (in October), and AMD (Asynchronous Module Definition) is said to be far superior to CommonJS modules.

Update: As of December 2013, this has been supported again.

Javascript Solutions


Solution 1 - Javascript

Jeremy gave his reasoning in the comments of the commit:

> Yep. Not supporting a particular script loader will definitely make it easier for all of them to work properly. > > I apologize for merging the support in the first place.

He also tweeted a bit more on the change (link from a later comment):

> … because AMD support is breaking regular Underscore embeds on pages that also happen to use Require.js …

Solution 2 - Javascript

The developers of Underscore thought that having AMD support would break support on non-AMD enabled scripts. This is actually not the case, as you can have a script that is both AMD-enabled but also works as-is on a non-AMD deployment.

There is now a drop-in replacement for Underscore: Lo-Dash. Which, along with other features not in Underscore, includes AMD/non-AMD duality.

Solution 3 - Javascript

I felt the need to add to this fairly old question.

Both Backbone and Underscore now support AMD:

  1. Underscore commit
  2. Backbone Commit

Discussions (albeit Backbone's one is a bit puzzling as there is a clear discrepancy between the tone of the discussion and the actual outcome):

  1. Underscore Issue
  2. Backbone Issue

Solution 4 - Javascript

ES5-shim provides many of the same features as underscore and lodash (array.forEach(), array.map() etc).

ES5-shim natively supports AMD, unlike underscore and lodash, doesn't add extra copies of things your browser probably already provides. Rather it adds native ES5 features to older browsers.

When IE8 and other older browsers die out, you can simply remove the ES5-shim dependency without having to port code like you would with lodash or underscore.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionc69View Question on Stackoverflow
Solution 1 - JavascriptJonathan LonowskiView Answer on Stackoverflow
Solution 2 - JavascriptAngelos PikoulasView Answer on Stackoverflow
Solution 3 - JavascriptZenMasterView Answer on Stackoverflow
Solution 4 - JavascriptmikemaccanaView Answer on Stackoverflow