Facade module design pattern

28 views
Skip to first unread message

Aubin Lorieux

unread,
Mar 5, 2015, 9:47:50 AM3/5/15
to nod...@googlegroups.com
I everyone,

I'm making a module to wrap up the module soap. I want to expose a specific but simple API.

var myModule = require('myModule');
var webservice = myModule({someOptions: ''});

webservice
.run(data, function(err, res){
 
//Do something
});

It is a good practice to return an instance of protoype by module.exports.

function MyModule(options) {
 
this.options = options || options;
};

MyModule.prototype.myFunc = function() {

};

module.exports = exports = function(options) {
 
return new MyModule(options);
}

Thanks in advance

Aria Stewart

unread,
Mar 5, 2015, 11:30:04 AM3/5/15
to nod...@googlegroups.com
This makes the fact that you have a class behind the scenes a private detail to some degree, which I find nice. I'm a fan of new-less APIs. It makes it somewhat hard to subclass, and usually that's a good thing. Inheritance stinks as an extension mechanism.
Reply all
Reply to author
Forward
0 new messages