Skip to content

Instantly share code, notes, and snippets.

@seanstrom
Created December 23, 2014 23:10
Show Gist options
  • Save seanstrom/dbcd666edafd8c710458 to your computer and use it in GitHub Desktop.
Save seanstrom/dbcd666edafd8c710458 to your computer and use it in GitHub Desktop.
Exploring Constructors and Factories in Javascript - Refactored Constructor Example
var Person = require('./person')
var options = {name: 'Sean Hagstrom', age: 20}
var sean = new Person(options)
console.log(sean.name) // Sean Hagstrom
console.log(sean.age) // 20
function Person(opts) {
this.name = opts.name
this.age = opts.age
}
module.exports = Person
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment