> On Mar 5, 2015, at 3:38 AM, Aubin Lorieux <[email protected]> wrote:
> 
> 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);
> }


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.

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/8E0B7B15-46A0-47A6-8E01-EB3AED95A2EC%40nbtsc.org.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to