Last active
August 29, 2015 14:12
-
-
Save seanstrom/651b60870e110c0650a4 to your computer and use it in GitHub Desktop.
Exploring Constructors and Factories in Javascript - Using Object.create
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
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. |
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 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