Skip to content

Instantly share code, notes, and snippets.

@ideodora
Last active August 29, 2015 14:10
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 ideodora/051b6af17069ca99425e to your computer and use it in GitHub Desktop.
Save ideodora/051b6af17069ca99425e to your computer and use it in GitHub Desktop.
module.exports で インスタンスとクラス両方返す方法?
// export the function that instantiate the class and return it with same option
module.exports = function foo(opts) {
return new Foo(opts);
};
module.exports.Foo = Foo;
var foo = require('foo') // foo is isntance
var Foo = require('foo').Foo // Foo is class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment