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.

Pawan
  • 605
  • 1
  • 6
  • 18
c69
  • 19,951
  • 7
  • 52
  • 82
  • 2
    I hope you can link to a post, mail discussion, or twitter comment with motivation for this act or clarification from developers. – c69 Jan 25 '12 at 20:08
  • 1
    *Asynchronous Module Definition* not *Advanced module loader*, see https://github.com/amdjs/amdjs-api/wiki/AMD – Jacob Oscarson Jan 26 '12 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. – Jess Jacobs Apr 18 '12 at 17:15

4 Answers4

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 …

Community
  • 1
  • 1
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199
  • 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? – Jonathan Lonowski Jun 08 '12 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. – Samuel Katz Jun 08 '12 at 18:00
  • 5
    @SalmanPK Use a fork that's dedicated to Underscore for AMD, then: https://github.com/amdjs/underscore. – Jonathan Lonowski Jun 08 '12 at 18:37
  • 7
    **Note: As now mentioned in the question, Underscore is AMD compliant again, as of December 2013.** – Brad Parks Mar 13 '14 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.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Angelos Pikoulas
  • 1,002
  • 1
  • 14
  • 21
  • 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. – Brian M. Hunt Jul 28 '12 at 19:11
  • lodash sounds cool, but I don't see how this answers the question – Zach Lysobey Apr 01 '13 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 – Angelos Pikoulas Apr 04 '13 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
ZenMaster
  • 12,363
  • 5
  • 36
  • 59
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.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
  • 2
    the question was not about features of underscore library, but rather about _reasons_ for such (controversial / opaque) architectural choice. – c69 Jan 19 '13 at 01: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. – mikemaccana Apr 03 '13 at 10:43