没有密钥,module.exports对象如何工作?

module.exports对于没有键的对象如何工作?例如,如果我在test.js

const two = 2;
const three = 3;
module.exports = {two,three};    // Is the right-hand side an object? If so,where are its keys?
                                  // It doesn't look like it's object destructuring.

app.js

const test = require("./test");
console.log(test.two);            // 2
console.log(test.three);          // 3
qq13903156070 回答:没有密钥,module.exports对象如何工作?

此:

module.exports = {two,three};

是以下内容的简写形式:

module.exports = {two: two,three: three};

两者都生成完全相同的对象。这与module.exports无关。这只是在ES6 object initializer处声明对象的简写方式,您希望该对象的属性名称与变量名称相同。

本文链接:https://www.f2er.com/2636894.html

大家都在问