If Child1
is supposed to refer to the "current" class, i.e. the class that defaultInstance
is invoked on, then you can just do
defaultInstance = new this();
This follows the normal JavaScript rules: If you invoke the function with Child1.defaultInstance()
, then this
refers to Child1
.
However, this probably doesn't do what you want. If you define defaultInstance
on the base class, then all child classes share the same defaultInstance
variable.
If you want to have an instance per class, then each class needs its own defaultInstance
method, or you need to use a property instead, e.g.
if (!this.__defaultInstance) {
this.__defaultInstance = new this();
}