Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuation of "function is not a function" bug #102

Merged
merged 2 commits into from
Feb 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,65 @@ new Foo() instanceof null;

This is not a part of the specification. It's just a bug that has now been fixed, so there shouldn't be a problem with it in the future.

### Super constructor null of Foo is not a constructor

It's continuation of story with previous bug in modern environment (tested with Chrome 71 and Node.js v11.8.0).

```js
class Foo extends null {}
new Foo() instanceof null;
// > TypeError: Super constructor null of Foo is not a constructor
```

### 💡 Explanation:

This is not a bug because:

```js
Object.getPrototypeOf(Foo.prototype); // -> null
```

If the class has no constructor the call from prototype chain. But in the parent has no constructor. Just in case, I’ll clarify that `null` is an object:

```js
typeof null === 'object'
```

Therefore, you can inherit from it (although in the world of the OOP for such terms would have beaten me). So you can't call the null constructor. If you change this code:

```js
class Foo extends null {
constructor() {
console.log('something');
}
}
```

You see the error:

```
ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
```

And if you add `super`:

```js
class Foo extends null {
constructor() {
console.log(111);
super();
}
}
```

JS throws an error:

```
TypeError: Super constructor null of Foo is not a constructor
```

- [An explanation of this issue](https://github.com/denysdovhan/wtfjs/pull/102#discussion_r259143582) by [@geekjob](https://github.com/geekjob)

## Adding arrays

What if you try to add two arrays?
Expand Down