Smurfette
Smurfette

Reputation: 2005

Why doesn't backbone use module.exports?

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.

Upvotes: 1

Views: 1772

Answers (2)

Phillip Schmidt
Phillip Schmidt

Reputation: 8818

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.

Upvotes: 1

Felix Kling
Felix Kling

Reputation: 816810

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).

Upvotes: 2

Related Questions