Subclassing Object
and using super()
class C extends Object {
constructor(v) {
super(v);
}
}
console.log(new C(1) instanceof Number); // false
Custom Wrapper Function:
function MyObject(v) {
return new Object(v);
}
class D extends MyObject {
constructor(v) {
super(v);
}
}
console.log(new D(1) instanceof Number); // true
I know MDN docs mention this that in directly subclassing Object
it ignores arguments but I’m still not able to understand it fully like why does it do so? What exactly is happening behind the scenes when super(v)
is used in a subclass extending Object
, and how does it differ from using a wrapper function that explicitly returns an object?