Skip to content

Instantly share code, notes, and snippets.

@Yago
Created November 28, 2018 12:56
Show Gist options
  • Save Yago/c23b52c307b262f1faf624cb32ffb2c0 to your computer and use it in GitHub Desktop.
Save Yago/c23b52c307b262f1faf624cb32ffb2c0 to your computer and use it in GitHub Desktop.
const sum = {
current: 0,
get result() {
return `The current result is ${this.current}`;
},
set add(n) {
if (typeof n === 'number') this.current = this.current + n;
}
};
sum.add = 31;
sum.add = 7;
sum.add = 4;
console.log(sum.result); // The current result is 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment