【Node】自定义模块和使用

自定义一个hello模块,并对外展现

hello.js文件内容:

function Hello(){
    var name;
    this.setName = function(thyName){
        name = thyName;
    };
    this.sayHello = function(){
        console.log('hello:'+name);
    };
};
module.exports =Hello;
主程序调用:

var Hello = require('./hello')
hello = new Hello();
hello.setName('wahahah');
hello.sayHello();


猜你喜欢

转载自blog.csdn.net/spy20008/article/details/79057180