Skip to content

Instantly share code, notes, and snippets.

@isaacs
Forked from niklasfi/foo.js
Created February 7, 2011 21:50
Show Gist options
  • Save isaacs/815301 to your computer and use it in GitHub Desktop.
Save isaacs/815301 to your computer and use it in GitHub Desktop.
module.exports = Foo;
//now i would like to have a constructor function for the foo "class" (i know in JS that does not exist)
//with normal js this would be
function Foo(arg1,arg2){
this.something = arg1;
this.somethingOther = arg2;
}
//but this would override exports, which defeats the purpose of putting this "class" in a different file
//would also like to do
Foo.prototype.fnc1 = function(args){
//do stuff
}
//i learned that declaring "static" functions this way is a good practice in JS. Is that also possible with require?
var Foo = require('./foo.js');
var foo1 = new Foo("x","y");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment