Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript module.exports对象在没有键的情况下如何工作?_Javascript_Node.js_Node Modules - Fatal编程技术网

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中引入的对象创建简写方式