I have a class like the following:
const Module = {
Example: class {
constructor(a) {
this.a = a;
}
static fromString(s) {
return new Module.Example(a);
}
}
}
This still works, but accessing the current class constructor using a global name Module.Exampleis pretty ugly and prone to cracking.
In PHP, I would use new self()either new static()here to refer to the class in which the static method is installed. Is there something similar in Javascript that is independent of the global scope?
source
share