this.#staticAntall"
doesn't refer to the class, and therefore returns an error.
Is this referring to the constructor in that case?
And is there a reference I can use to refer to the class(since I am going to write multiple classes it would be nice to not have to have class referrences from names.
Allergy.js:32 Uncaught TypeError: Cannot read private member #staticAntall from an object whose class did not declare it
I wish to just write this.#staticAntall ++;
or return this.#staticAntall;
It seems like I am having problems with the way I use static too. Here I want to count the number of GlutenIntoleranse-classes So that I can use that value afterwards.
What does the #
infront of static
stand for?
at new GlutenIntoleranse (Allergy.js:32)
at <anonymous>:1:10
class Allergy {
constructor(name, tag, description, advice) {
this.name = name || "Ingen navn";
this.tag = tag || "Ingen forkortelse";
this.description = description || "Ingen beskrivelse";
this.advice = advice || "Ingen råd";
}
//methods...
}
class GlutenIntoleranse extends Allergy {
static #staticAntall = 0;
constructor() {
super("GlutenIntoleranse", "GLT-I", "Gluten intoleranse", "Skal ikke serveres gluten");
increaseAntall();
//GlutenIntoleranse.#staticAntall++;
this.#staticAntall += 1;
console.log(GlutenIntoleranse.#staticAntall);
}
increaseAntall() {
GlutenIntoleranse.#staticAntall++;
}
}