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
MYYA
相关分类