Skip to content

Instantly share code, notes, and snippets.

@telekosmos
Last active August 23, 2019 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telekosmos/cb28441d9598553bbef11c526317ca5b to your computer and use it in GitHub Desktop.
Save telekosmos/cb28441d9598553bbef11c526317ca5b to your computer and use it in GitHub Desktop.
ES6 POJOs
// 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