node 自定义模块
2019-03-12 本文已影响0人
遥啊遥啊遥啊
自定义模块
main.js(调用)
let Hello = require('./hello'); hello = new Hello(); hello.setname('yaoyaoyao'); hello.sayname();
hello.js(模块)
function Hello() {
let name;
this.setname = function (getname) {
name = getname;
};
this.sayname = function () {
console.log('hello' + name);
};
};
module.exports = Hello;