Skip to content

Add support for registering Backbone as an AMD Module.  #684

@treasonx

Description

@treasonx

Underscore 1.2 will properly register itself as an AMD module if it detects an amd loader. If you load underscore 1.2 with an AMD loader and then try to load Backbone, Backbone will fail because underscore will not exist in the global scope.

Backbone should do a similar check and asynchronously load underscore as a dependency.

Prior to underscore 1.2 I would use underscore and backbone with RequireJS like so.

define(['modile1', 'order!underscore', 'order!backbone'], function(Module1) {
  //Do stuff here. Backbone and underscore would be global
});

Now if I do the following with underscore 1.2

define(['modile1', 'order!underscore', 'order!backbone'], function(Module1, _, Backbone) {
  //I can load underscore properly because it is amd aware but Backbone will fail 
  //due to underscore not being in the global scope
});

If Backbone was AMD aware like underscore we could just do the following

define(['modile1', 'backbone'], function(Module1, Backbone) {
  //Backbone loads properly and pulls in underscore as its dependency
});

I have modified Backbone on my own branch to check for an AMD loader and load underscore 1.2 properly. Unit tests still pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions