80 lines
1.2 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
In the constructor of a derived class, accessing ``++this++`` or ``++super++`` before ``++super()++`` is called raises a reference error. ``++super()++`` should always be called first.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
class Bar {
}
class Foo extends Bar {
constructor() {
this.val = 0; // Noncompliant
super();
}
}
class Foobar extends Foo {
constructor() {
super.val = 1; // Noncompliant
super();
}
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
class Bar {
}
class Foo extends Bar {
constructor() {
super();
this.val = 0;
}
}
class Foobar extends Foo {
constructor() {
super();
super.val = 1;
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Move this statement after the call to "super()" or remove it.
=== Highlighting
Primary: Statement with "this." or "super."
Secondary: Call to "super()"
'''
== Comments And Links
(visible only on this page)
=== on 24 Jan 2017, 13:15:59 Yves Dubois-Pèlerin wrote:
This RSPEC is superseded by RSPEC-3854.
endif::env-github,rspecator-view[]