Skip to content

Instantly share code, notes, and snippets.

@mmfilesi
Created May 5, 2016 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmfilesi/92071841bdc6652dfec8460f6a1cce9c to your computer and use it in GitHub Desktop.
Save mmfilesi/92071841bdc6652dfec8460f6a1cce9c to your computer and use it in GitHub Desktop.
3 node modules patterns
'use strict';
function Foo(numParam) {
this.bar = numParam || 0;
}
Foo.prototype.publicMethod = function() {
let temp = 1 + this.bar;
return temp;
};
module.exports = Foo;
/* use:
const Foo = require('./foo');
let instFoo = new Foo(4);
console.log(instFoo.publicMethod());
*/
'use strict';
function Foo(numParam) {
this.bar = numParam || 0;
}
Foo.prototype.publicMethod = function() {
let temp = 1 + this.bar;
return temp;
};
module.exports = new Foo(5);
/* use:
const instFoo = require('./foo');
console.log(instFoo.publicMethod());
*/
'use strict';
const foo = (function() {
const module = {};
const self = module;
module._privateMethod = (numParam)=> {
let temp = 1 + numParam;
return temp;
};
module.publicMethod = (numParam)=> {
let bar = self._privateMethod(numParam);
return bar;
};
return {
publicMethod: module.publicMethod
};
} )();
module.exports = foo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment