Last active
April 22, 2016 13:41
-
-
Save assertnotnull/be15ca7e71b1c7a8c514363d10a681de to your computer and use it in GitHub Desktop.
Ways to define modules in node
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
var onedep = require('one'); | |
var self; | |
function AsClass(param) { | |
this.param = param; | |
} | |
AsClass.prototype.doSomething(param) { | |
console.log('can access',self.param); | |
onedep('whatever', function() { | |
console.log('can access', self.param); | |
}) | |
} | |
module.exports = AsClass; |
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
var onedep = require('one'); | |
var commonvalue; | |
function AsClass(initial) { | |
var othervalue = 1; | |
commonvalue = initial; | |
function doSomething(value) { | |
console.log(commonvalue); | |
} | |
function doSomethingElse(value) { | |
console.log(othervalue); | |
} | |
return { | |
exposeDoSomething: doSomething | |
exposeDoSomethingElse: doSomethingElse | |
} | |
} | |
module.exports = AsClass; |
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
var onedep = require('one'); | |
module.exports = function(initial) { | |
function AsClass(intial) { | |
this.doSomething = function(params) { | |
console.log(params) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment