1

It looks like it uses just plain

exports instead of module.exports

in this line here.

if (typeof exports !== 'undefined') {
    Backbone = exports;

However this tutorial shows the module.exports being used.

Smurfette
  • 1,935
  • 2
  • 14
  • 15
  • `exports` and `module.exports` are the same. – Felix Kling Aug 12 '13 at 19:46
  • ... not sure if this is related ... http://stackoverflow.com/questions/7137397/module-exports-vs-exports-in-nodejs ... http://stackoverflow.com/questions/5311334/what-is-the-purpose-of-nodejs-module-exports-and-how-do-you-use-it – Smurfette Aug 12 '13 at 19:50
  • Looks like module is the global variable. Kind of like window is the global variable when on the browser/client. Why then is the code not Backbone = root.exports. In this case, root will point to module. global to each file. or local to each file. however you want to put it. – Smurfette Aug 12 '13 at 19:57

2 Answers2

2

Why doesn't backbone use module.exports?

Because it doesn't have to. exports and module.exports refer to the same object:

In particular module.exportsis the same as the exports object.

If you can save a couple of characters to type, then why not do it?

You are doing the same when you use document.getElementById instead of window.document.getElementById. It's more to type and doesn't add any benefit.


In the tutorial they are using module.exports because they want to show the difference between exporting a symbol why exports, i.e.

exports.foo = bar;

and overwriting the exports object

module.exports = bar;

for which you have to use module.exports (exports = bar; would not work).

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
1

Think of module like window in a browser. In actuality, they're basically the same thing.

So, in the same way that window.location === location in javascript executed in the browser, module.exports === exports in a node environment.

Phillip Schmidt
  • 8,805
  • 3
  • 43
  • 67