Created
November 28, 2018 12:56
-
-
Save Yago/c23b52c307b262f1faf624cb32ffb2c0 to your computer and use it in GitHub Desktop.
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
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