Skip to content

Instantly share code, notes, and snippets.

@shisama
Created April 23, 2019 17:26
Show Gist options
  • Save shisama/a7ff7539f406789048a01af56feec4a7 to your computer and use it in GitHub Desktop.
Save shisama/a7ff7539f406789048a01af56feec4a7 to your computer and use it in GitHub Desktop.
Class Fields - New JavaScript Features in Node.js v12
class IncreasingCounter {
#count = 0;
get value() {
console.log('Getting the current value!');
return this.#count;
}
increment() {
this.#count++;
}
}
const counter = new IncreasingCounter();
// counter.#count; // is Error
counter.increment();
console.log(counter.value); // print '1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment