I have some classes:
class Sample{
static createSelf() {
return new this.constructor(1, 2);
}
}
class AnotherClass extends Sample {
constructor(a, b) {
this.c = a+b;
}
}
ac = AnotherClass.createSelf();
How do I do this?
This concrete example gives me SyntaxError: missing formal parameter, although in my original code (500 lines), when I have new this.constructor(), I get SyntaxError: missing ] after element list pointed at the first line (the formal parameter error is pointed at line 1, too). I know it is because of this line, as when I replace it with a normal class name, it works. There is no Array initialization close. The error cannot possibly mean:
There is an error with the array initializer syntax somewhere. Likely there is a closing bracket ("]") or a comma (",") missing.
from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Missing_bracket_after_list
UPDATE original code:
class Participant {
constructor(origin, destination, number, startDate, endDate) {
...
}
static restore(save) {
const participant = new this.constructor(
new Marker(save.originLocation, this.getMarkerOptions(true, save.isDriver, save.number)).addTo(map),
new Marker(save.destinationLocation, this.getMarkerOptions(false, save.isDriver, save.number)).addTo(map),
save.number,
save.startDate,
save.endDate
);
return participant;
};
}
class Driver extends Participant {}
d = Driver.restore(saveObject);