-
-
Save pifantastic/4355571 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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; |
This file contains hidden or 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
// 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