Last active
August 23, 2019 07:57
-
-
Save telekosmos/cb28441d9598553bbef11c526317ca5b to your computer and use it in GitHub Desktop.
ES6 POJOs
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
// doesn't work | |
const counter = { | |
val: 0, | |
next: () => ++this.val, // eslint-disable-line no-plusplus | |
}; | |
counter.val; // 0 | |
counter.next(); | |
counter.val; // 0 | |
// DOES work | |
const counterObj = { | |
val: 0, | |
next() { | |
return ++this.val; | |
}, | |
}; | |
counter.val; // 0 | |
counter.next(); | |
counter.val; // 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment