嗨,我是NodeJS的新手,我的node.js代码不起作用,因此,当我运行Node app.js
时,它仅返回“ [Function]”
//This is the index.js file
var number, origin, destination;
exports.setNumber = function (num){
number = num;
};
exports.setOrigin = function (o){
origin = o;
};
exports.setDestination = function (d){
destination = d;
};
exports.getInfo = function(){
return{
number : number,
origin : origin,
destination : destination
};
};
//This is the app.js file
var flight = require('./javascript_1')
flight.setNumber(356);
flight.setDestination('There');
flight.setOrigin('Here');
console.log(flight.getInfo);
请帮助,因为我不知道我在做什么错
答案 0 :(得分:1)
flight.getInfo
是一个函数。您必须调用它。尝试将最后一行替换为:
console.log(flight.getInfo());