Register as AMD module, but still export a global #431

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants
@jrburke
Contributor

jrburke commented Jan 11, 2012

This is in response to this commit, which came out of reports of issues using underscore in an AMD environment.

From what I have heard, the issues are mainly when trying to also use backbone. Those issues could be resolved by merging this pull request.

But in general, if underscore prefers to not get reports of issues with an AMD loader, this pull request also exports a global even if define() is available. This is the same approach that jQuery uses. Ideally this would not be needed, but modular development is just getting bootstrapped on the web, and during this bootstrap period, this approach avoids issues.

If pull requests are not the way you prefer to have this conversation, please let me know what avenue works best.

@jashkenas

This comment has been minimized.

Show comment
Hide comment
@jashkenas

jashkenas Jan 11, 2012

Owner

Thanks for the pull request, but I'm afraid that I've been mulling over this issue since the original AMD commit, and have pretty well decided on yanking it.

Since the original AMD addition, I think that the volume of confused users trying to load Underscore correctly has only increased. There have been any number of things:

  • Folks requesting other module formats for other loaders.
  • If any library that depends on Underscore (and there are many of them: http://search.npmjs.org/) does not yet 'support' AMD, but Underscore does, things get royally screwed up.
  • In an ideal situation, libraries do not have to be modified to support a particular script loader (or group of loaders).
  • JavaScript's upcoming native module support is entirely incompatible with AMD.
  • Loading individual modules piecemeal is a terrifically inefficient way to built a website. Because of this, there's the great RequireJS optimizer, which will turn your modules into ordinary packages.

If JavaScript ever gets a real module system, and that module system is deployed in cross browser, we'll support it. Until that day, you can:

  • Use one of the many script loaders that doesn't require every script you load to be rewritten.

  • Patch your copy of Underscore.js

  • Use a fork, perhaps provided by @jrburke.

  • Use a little RequireJS shim, like this one:

    define(['vendor/underscore', 'vendor/jquery', 'order!vendor/backbone'], function() {
      return Backbone;
    });
    
Owner

jashkenas commented Jan 11, 2012

Thanks for the pull request, but I'm afraid that I've been mulling over this issue since the original AMD commit, and have pretty well decided on yanking it.

Since the original AMD addition, I think that the volume of confused users trying to load Underscore correctly has only increased. There have been any number of things:

  • Folks requesting other module formats for other loaders.
  • If any library that depends on Underscore (and there are many of them: http://search.npmjs.org/) does not yet 'support' AMD, but Underscore does, things get royally screwed up.
  • In an ideal situation, libraries do not have to be modified to support a particular script loader (or group of loaders).
  • JavaScript's upcoming native module support is entirely incompatible with AMD.
  • Loading individual modules piecemeal is a terrifically inefficient way to built a website. Because of this, there's the great RequireJS optimizer, which will turn your modules into ordinary packages.

If JavaScript ever gets a real module system, and that module system is deployed in cross browser, we'll support it. Until that day, you can:

  • Use one of the many script loaders that doesn't require every script you load to be rewritten.

  • Patch your copy of Underscore.js

  • Use a fork, perhaps provided by @jrburke.

  • Use a little RequireJS shim, like this one:

    define(['vendor/underscore', 'vendor/jquery', 'order!vendor/backbone'], function() {
      return Backbone;
    });
    

@jashkenas jashkenas closed this Jan 11, 2012

@rstacruz rstacruz referenced this pull request in theironcook/Backbone.ModelBinder Oct 2, 2012

Closed

Remove AMD/require.js support #83

@timmywil timmywil referenced this pull request in jashkenas/backbone Jun 27, 2013

Closed

Reconsider AMD support #2641

@davidchambers davidchambers referenced this pull request in davidchambers/airwaves Jun 30, 2013

Closed

Adding AMD support #1

@bibz bibz referenced this pull request Oct 8, 2013

Closed

UMD-ready Underscore #1303

@josh josh referenced this pull request in josh/selector-set Jan 26, 2014

Closed

Add UMD wrapper that works with browser/amd #9

@basarat basarat referenced this pull request in DefinitelyTyped/DefinitelyTyped Feb 7, 2014

Merged

Export as "backbone" module for AMD loading #1673

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment