Created
May 5, 2016 05:29
-
-
Save mmfilesi/92071841bdc6652dfec8460f6a1cce9c to your computer and use it in GitHub Desktop.
3 node modules patterns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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()); | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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()); | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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