在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ nodejs module.exports 如何引用一個類原型中的方法

nodejs module.exports 如何引用一個類原型中的方法

a.js
這是node導出一個類
let Person = function () {

this.name = '張三;

}
Person.prototype = {

constructor:Person,
say:function () {
    console.log('my name is '+this.name);
}

};
module.exports.Person = Person;
b.js
引用a.js文件
let Person = require("./a.js");
let person = new Person('張三');
console.log(person.say());

為什么最后輸出 my name is 張三 和undefined

回答
編輯回答
抱緊我

person.say() 是一個沒有任何返回的方法
你直接 console.log(person.say()) 當然是undefined了

2017年8月14日 04:59