class MockFamily implements IFamily {
static instances: MockFamily[] = [];
constructor (nodeClass: { new (): Node; }, engine: Engine) {
MockFamily.instances.push(this);
}
/* sniiiiiip */
}
In the above example is there any way to access the static instances
value from within the constructor without using the actual class name?
Static variables are always accessed trough the class-name. The class object acts as an object with properties. The closest you could come is maybe:
with (MockFamily) {
instances.push(this);
}
Though I would not recommend it.
Modules are another thing though. At run-time, their contents are variables in a function scope, and can be accessed directly almost anywhere within.
module MyModule {
var instances: IFamily[] = [];
export class MockFamily implements IFamily {
constructor (nodeClass: { new (): Node; }, engine: Engine) {
instances.push(this);
}
/* sniiiiiip */
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With