节点在命令行中返回“ [Function]”

时间:2019-01-22 11:01:52

标签: javascript node.js

嗨,我是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);

请帮助,因为我不知道我在做什么错

1 个答案:

答案 0 :(得分:1)

flight.getInfo是一个函数。您必须调用它。尝试将最后一行替换为:

console.log(flight.getInfo());