Skip to content

Instantly share code, notes, and snippets.

@davidrhyswhite
Last active August 25, 2016 23:04
Show Gist options
  • Save davidrhyswhite/2984d58a9fc43c3424354e2cdd18ab0b to your computer and use it in GitHub Desktop.
Save davidrhyswhite/2984d58a9fc43c3424354e2cdd18ab0b to your computer and use it in GitHub Desktop.
For the Medium article on Object.defineProperty
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