65

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.

3
  • 2
    I hope you can link to a post, mail discussion, or twitter comment with motivation for this act or clarification from developers.
    – c69
    Commented Jan 25, 2012 at 20:08
  • 1
    Asynchronous Module Definition not Advanced module loader, see github.com/amdjs/amdjs-api/wiki/AMD Commented Jan 26, 2012 at 15:40
  • 1
    so far, the most prominent voice of AMD being said to be far superior to commonjs/etc is the creator of require.js himself. i'm less inclined to take blindly the opinions of the creator of a particular method than i am to listen to a community of people, and thus far, the jury's still out. Commented Apr 18, 2012 at 17:15

4 Answers 4

56

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 …

4
  • 2
    @SalmanPK This change just means that underscore is loader-agnostic now. So, you're free to set it up for any loader you need. How is that a bad thing? Commented Jun 8, 2012 at 17:46
  • 3
    Because now we can't use it with any AMD compatible loader (RequireJS, Almond.js, curl.js, lsjs, bdLoad, Yabble etc) without extra configuration or manual editing.
    – Salman
    Commented Jun 8, 2012 at 18:00
  • 5
    @SalmanPK Use a fork that's dedicated to Underscore for AMD, then: github.com/amdjs/underscore. Commented Jun 8, 2012 at 18:37
  • 7
    Note: As now mentioned in the question, Underscore is AMD compliant again, as of December 2013.
    – Brad Parks
    Commented Mar 13, 2014 at 16:15
29

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.

3
  • 17
    I think this answer is underrated. However, I feel the tone of this answer (intentional or not) is condescending towards the underscore developers, which I do not think is appropriate. Commented Jul 28, 2012 at 19:11
  • lodash sounds cool, but I don't see how this answers the question Commented Apr 1, 2013 at 18:15
  • I agree with both of you - it doesn't really answer on the 'why'. Instead it quickly gives a drop-in alternative. So I am editing the answer a little bit Commented Apr 4, 2013 at 18:52
10

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
0
1

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.

2
  • 2
    the question was not about features of underscore library, but rather about reasons for such (controversial / opaque) architectural choice.
    – c69
    Commented Jan 19, 2013 at 1:55
  • @c69 Understood, but the lodash answer also doesn't cover the reasons for removing AMD from underscore. Since that answer is highly moderated, I thought pointing out that using ES5 itself / ES5 shim for older browsers presents a more future-safe alternative. Commented Apr 3, 2013 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.