Return a more descriptive error message than "|this| used uninitialized in ... constructor"

NEW
Unassigned

Status

()

Core
JavaScript Engine
12 days ago
12 days ago

People

(Reporter: sole, Unassigned)

Tracking

(Blocks: 1 bug)

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

If you try to use this in a class that inherits from another before calling super, you get a somewhat obscure error: "|this| used uninitialized in [insert class name here] constructor"

This caught me off guard and confused me to no end for a while.

Perhaps we should add something like "Please call super() before accessing |this| on a constructor"?

Examples -- the following causes the error.

```
class A extends B {
  constructor() {
    this.someVariable = 'some value'; // fails
  }
}
```

and the following doesn't.

```
class A extends B {
  constructor() {
    super(); // ☜☜☜ ❗️❗️❗️
    this.someVariable = 'some value'; // works!
  }
}
```
Blocks: 622261
FWIW in Safari I get: ReferenceError: Cannot access uninitialized variable.

And Chrome: ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
You need to log in before you can comment on or make changes to this bug.