gpt4 book ai didi

javascript - 为什么 backbone 不使用 module.exports?

转载 作者:行者123 更新时间:2023-11-30 12:58:32 26 4
gpt4 key购买 nike

看起来它只是简单地使用

exports 而不是 module.exports

在这一行here .

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

然而这tutorial显示正在使用的 module.exports

最佳答案

Why doesn't backbone use module.exports?

因为没有必要。 exports and module.exports refer to the same object :

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

如果您可以节省几个字符来输入,那为什么不这样做呢?

当您使用 document.getElementById 而不是 window.document.getElementById 时,您也在做同样的事情。打字更方便,不会增加任何好处。


在教程中,他们使用了 module.exports,因为他们想展示导出符号与为什么要导出 exports 之间的区别,即

exports.foo = bar;

覆盖 exports 对象

module.exports = bar;

必须使用module.exports(exports = bar; 将不起作用)。

关于javascript - 为什么 backbone 不使用 module.exports?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18195399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com