Skip to content

Instantly share code, notes, and snippets.

@ralphholzmann
Created August 1, 2011 14:57
Show Gist options
  • Save ralphholzmann/1118285 to your computer and use it in GitHub Desktop.
Save ralphholzmann/1118285 to your computer and use it in GitHub Desktop.
exports.prop vs module.exports for a constructor
// 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" );
// 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" );
// 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