nodejs module/require

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();

 

posted @ 2015-03-25 23:34  zyip  阅读(151)  评论(0编辑  收藏  举报