nodeJS:module.exports = {x:f(n)}不工作,但module.exports.x = f(n)正在工作

问题描述:

我在学习节点,我不确定在哪里出错module.exports:nodeJS:module.exports = {x:f(n)}不工作,但module.exports.x = f(n)正在工作

所以我在我的test.js文件如下:

let test = require('./app'); 
test.age(); 
test.testage(); 

我也有这个在我的app.js文件:

module.export = { 
    age: function(){ 
    console.log(1); 
    } 
}; 

module.exports.testage = function(){ 
    console.log(1); 
} 

的test.age功能不工作('它说test.age不是一个函数')。另一方面,test.testage()工作正常。

有人可以解释这种情况吗?

+2

使用module.exports而不是module.export –

module.exports = { // exports instead of export 
    age: function(){ 
    console.log(1); 
} 

};

module.exports.testage = function(){ 
    console.log(1); 
} 
+0

是的,这是正确的。谢谢 –