Javascript module export structure

can someone explain what for export variable:

copied from backbone.js, I also noticed that spine.js uses the same template.

https://gist.github.com/1375748

var Backbone; if (typeof exports !== 'undefined') { Backbone = exports; } else { Backbone = root.Backbone = {}; } 
+7
source share
1 answer

This module template is part of the CommonJS specification called CommonJS Modules :

The module has a free variable called "export", that is, an object that the module can add to its API to execute.

Thus, basically adding an export object defines the API that your module provides.

+12
source

All Articles