-
-
Save ralphholzmann/1118285 to your computer and use it in GitHub Desktop.
exports.prop vs module.exports for a constructor
This file contains 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
// Boo | |
exports.Person = function( first, last ) { | |
this.first = first; | |
this.last = last; | |
}; | |
// In your app, you'd have to do | |
var Person = require( "person" ).Person, // woof. | |
me = new Person( "ralph", "holzmann" ); |
This file contains 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
// Yay! \o/ | |
module.exports = function( first, last ) { | |
this.first = first; | |
this.last = last; | |
}; | |
// Now you can simply do | |
var Person = require("person"), // omg, this is what I want | |
me = new Person( "ralph", "holzmann" ); |
This file contains 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
// Best! \o/ | |
var Person = function( first, last ) { | |
this.first = first; | |
this.last = last; | |
}; | |
module.exports = Person; | |
// Now you can simply do | |
var Person = require("person"), // omg, this is what I want | |
me = new Person( "ralph", "holzmann" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment