Skip to content

Instantly share code, notes, and snippets.

@seanstrom
Last active August 29, 2015 14:12
Show Gist options
  • Save seanstrom/651b60870e110c0650a4 to your computer and use it in GitHub Desktop.
Save seanstrom/651b60870e110c0650a4 to your computer and use it in GitHub Desktop.
Exploring Constructors and Factories in Javascript - Using Object.create
var Person = require('./person')
var sean = Object.create(Person.prototype, {
name: {
configurable: true, // defaults to false
enumerable: true, // defaults to false
writable: true, // defaults to false
value: 'Sean Hagstrom' // defaults to undefined
},
age: {
configurable: true,
enumerable: true,
writable: true,
value: 20
}
})
console.log(sean.greeter()) // Hello my name is Sean Hagstrom and I am 20 years old.
function Person() {}
Person.prototype.greeting = function() {
return 'Hello my name is ' + this.name + ' and I am ' + this.age + ' years old.'
}
module.exports = Person
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment