running the following code in node (v8.4)
class TodoStore {
todos = [];
get completedTodosCount() {
return this.todos.filter(
to
Instance class fields will be supported as of Node v12, so one solution is to use a version >= 12 once it is released.
https://node.green/#ESNEXT-candidate--stage-3--instance-class-fields
For now if you're interested the nightly builds are at: https://nodejs.org/download/nightly/
Update
Support for instance class fields starts with node >= 12.
Literal class properties are not supported by any version of node, according to this table. You'll still have to set any instance properties inside your class constructor:
class TodoStore {
constructor() {
this.todos = [];
}
// ...
}
If you wish to define a static
property, you'd assign that directly to the TodoStore
reference, after the class has been declared:
TodoStore.todos = [];