Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 2 commits into from
Closed

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

wants to merge 2 commits into from

Conversation

jrburke
Copy link
Contributor

@jrburke 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
Copy link
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;
    });
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants