Last active
August 25, 2016 23:04
-
-
Save davidrhyswhite/2984d58a9fc43c3424354e2cdd18ab0b to your computer and use it in GitHub Desktop.
For the Medium article on Object.defineProperty
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
var Person = function Person(firstName, lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
Object.defineProperty(this, 'fullName', { | |
get: function get() { | |
return this.firstName + ' ' + this.lastName; | |
} | |
}); | |
}; | |
var person = new Person('David', 'White'); | |
console.log(person.fullName); // David White |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment