node的模块系统
作者:bin封装模块demo:
//hello.js module.exports = function () { var name; this.setName = function(thyName) { name = thyName; }; this.sayHello = function() { console.log('Hello ' + name); }; };
当然也可以给方法命名,看你喜欢咯
function Helloo() {}; module.exports = Helloo;
模块使用:
var Hello = require('./he'); hello = new Hello(); hello.setName('nihao'); hello.sayHello();