Skip to content

Instantly share code, notes, and snippets.

@assertnotnull
Last active April 22, 2016 13:41
Show Gist options
  • Save assertnotnull/be15ca7e71b1c7a8c514363d10a681de to your computer and use it in GitHub Desktop.
Save assertnotnull/be15ca7e71b1c7a8c514363d10a681de to your computer and use it in GitHub Desktop.
Ways to define modules in node
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;
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;
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