This repository was archived by the owner on Jan 25, 2022. It is now read-only.
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
Order of execution with subclasses #54
Closed
Description
I understand why the current order is the way that it is, but I have a scenario I thought would be supported but currently is not.
Also, is there a people-targetted document which outlines the order? I only established the order from a combination of squinting at the spec and trying examples.
Consider the following example
class Base {
y = 7;
constructor(lots, of, args, that, are, a pain, to, repeat, when, defining, children) {
/**
Do work using all those constructor args
**/
this.init();
}
init() {
// extension point for subclasses so they don't have to pass along children
}
}
class Derived extends Base {
z = 4;
init() {
alert(this.z * this.y);
}
}
var q = new Derived();
The motivation was to avoid having children repeat the constructor signature - and potential errors caused by not passing along arguments correctly. When I attempted to use this approach I hit a snag, the execution order is:
- Base class properties
- Base class constructor
- init()
- Derived class properties
Is there any way to place an init routine somewhere after all class properties have been evaluated?
Metadata
Metadata
Assignees
Labels
No labels