Javascript module.exports对象在没有键的情况下如何工作?
对于没有键的对象,Javascript module.exports对象在没有键的情况下如何工作?,javascript,node.js,node-modules,Javascript,Node.js,Node Modules,对于没有键的对象,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 destruc
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.
const test = require("./test");
console.log(test.two); // 2
console.log(test.three); // 3
在app.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.
const test = require("./test");
console.log(test.two); // 2
console.log(test.three); // 3
这:
是以下各项的简写符号:
module.exports = {two: two, three: three};
两者生成完全相同的对象。这与
模块导出无关。这只是一种声明对象的简写方式,您希望属性名称与变量名称相同。这不是特定于模块的任何内容。exports
-这只是ES6中引入的对象创建简写方式