treasonx/backbone — comment on commit ff63b05d4dc22d4f05c688617d9e3cc30157ea52
File:  line 0
By treasonx:

Basically I am doing a minimal amount of setup work. Then depending on which environment the code is running in I am pulling in underscore as a dependency.

In a CommonJS environment like Node we can just call require('underscore') and get back a reference to underscore and continue setting up Backbone.

In the second case I am checking for an AMD loader. If there is one I need to asynchronously load underscore as a dependency. Underscore 1.2 is aware of AMD loaders and will return the reference properly. Once I get a reference to underscore I continue setting up the backbone object and return the reference to the backbone object.

The third case we assume a normal browser environment and load backbone like normal.

I used a wrapper function (_Backbone) to hold most of the code that constructs the Backbone object. I am not too happy with the name of the function so suggestions are welcome.

I had to shift most of the code into the _Backbone function and do a minimal setup and environment detection before calling it.