Skip to content

Instantly share code, notes, and snippets.

@pifantastic
Forked from cowboy/thing.js
Last active December 10, 2015 00:59
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 pifantastic/4355571 to your computer and use it in GitHub Desktop.
Save pifantastic/4355571 to your computer and use it in GitHub Desktop.
function Thing(prop) {
this.prop = prop;
}
Thing.prototype.toString = function() {
return "My prop is: " + this.prop;
};
module.exports = function (opts) {
return new Thing(opts);
}
module.exports.Thing = Thing;
// Option one:
var Thing1 = require("./thing").Thing;
var thing1 = new Thing1("foo");
String(thing1) // "My prop is: foo"
// Option two:
var thing2 = new(require("./thing"))("bar");
String(thing2) // "My prop is: bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment