2
I’m testing new JS features, but my Vscode can’t detect that the project uses the new private field syntax. The code is like this:
entities.js
class Person {
constructor(p = {}) {
if(p) Object.assign(this, p)
}
#id
get id() { return this.#id }
set id(v) { this.#id = v }
#name
get name() { return this.#name }
set name(v) { this.#name = v }
#age
get age() { return this.#age }
set age(v) { this.#age = v}
}
Based on the documentation, by using this code I can create a class that:
- Allows the passage of properties as initial values
- Allows me to have hidden fields (the fields starting with old game)
- Enables encapsulation of properties
- Enables more coherent and clean OO work.
For me to work on the code I’m using Vscode only it can’t read this way of writing and keeps telling me that the code is incorrect:
What I need to do to make you understand what I’m writing?