Skip to content

Instantly share code, notes, and snippets.

@TommyZG
Created November 12, 2017 10:23
Show Gist options
  • Save TommyZG/d6fb17632d701794ab0062c37a8294da to your computer and use it in GitHub Desktop.
Save TommyZG/d6fb17632d701794ab0062c37a8294da to your computer and use it in GitHub Desktop.
let person = {
_name: 'Lu Xun',
_age: 137,
set age(newAge) {
if (typeof newAge === 'number') {
this._age = newAge;
} else {
return 'Invalid input'
}
},
get age() {
console.log(this._name + ' is ' + this._age + ' years old.')
return this._age
}
};
person.age = 39
console.log(person.age);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment