// Declare a class which extends null
class Foo extends null {}
// -> [Function: Foo]
new Foo() instanceof null;
// > TypeError: function is not a function
Not a bug! Because it is feature:
console.dir(Object.getPrototypeOf(Foo.prototype)); // is 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. 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:
class Foo extends null {
constructor() {
console.log(111);
}
}
You se the error:
ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
Not a bug! Because it is feature:
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. 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:
You se the error:
And if add super:
JS throw error:
This is my explanation based on my experience and understanding how the JS works.