I have a class like the following:
const Module = {
Example: class {
constructor(a) {
this.a = a;
}
static fromString(s) {
// parsing code
return new Module.Example(a);
}
}
}
This works so far, but accessing the current class constructor via the global name Module.Example
is kind of ugly and prone to breaking.
In PHP, I would use new self()
or new static()
here to reference the class that the static method is defined in. Is there something like this in Javascript that doesn't depend on the global scope?