nodejs module/require

zyip發表於2015-03-25

1. wrap up a module using module.exports, name the file to a.js

var fun1=function(){

var stylus = require('stylus');

this.hi=function(){
    console.log('hi');
}


}

fun1.prototype.hello=function(){
    console.log("abcdefg");
}


module.exports=fun1;

 

2. load module using rquire function

var a=require('./a');

var instanceA=new a();

instanceA.hi();

instanceA.hello();

 

相關文章