this
should be accessed after calling super
in constructor of inherited class
- ACCESS_THIS_BEFORE_SUPER_CALL
- Error
- High
- es6
This rule applies when this
is accessed before calling super
in constructor of inherited class.
When instantiating an inherited class, this
is bound in super
call. Therefore, accessing this
before calling super
throws a ReferenceError
exception.
For more information, please see super.
Noncompliant Code Example
View with compliant examples side by sideclass A {
constructor() {}
}
class B extends A {
constructor() {
this.a = 1;
super(); // ACCESS_THIS_BEFORE_SUPER_CALL alarm
}
}
new B();
Compliant Code Example
View with noncompliant examples side by sideclass A {
constructor() {}
}
class B extends A {
constructor() {
super();
this.a = 1;
}
}
new B();
Version
This rule was introduced in DeepScan 1.0.0-alpha.