简体   繁体   English

为什么主干不使用module.exports?

[英]Why doesn't backbone use module.exports?

It looks like it uses just plain 它看起来像只使用普通

exports instead of module.exports exports而不是module.exports

in this line here . 在这条线在这里

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

However this tutorial shows the module.exports being used. 但是,本教程显示正在使用的module.exports

Why doesn't backbone use module.exports? 为什么主干不使用module.exports?

Because it doesn't have to. 因为它没有。 exports and module.exports refer to the same object : exportsmodule.exports引用相同的对象

In particular module.exports is the same as the exports object. 特别是module.exportsexports对象相同。

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 . 使用document.getElementById而不是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 , ie 在本教程中,他们使用的是module.exports因为他们想显示出口的象征,为什么之间的差额exports ,即

exports.foo = bar;

and overwriting the exports object 覆盖 exports对象

module.exports = bar;

for which you have to use module.exports ( exports = bar; would not work). 必须使用module.exportsexports = bar;不起作用)。

Think of module like window in a browser. 在浏览器中考虑像window一样的module 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. 因此,与浏览器中执行的javascript中的window.location === location相同, module.exports === exports在节点环境中module.exports === exports

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM