Skip to content

Console output for class instance __proto__ seems wrong #33419

@hashseed

Description

@hashseed

Consider following code

class A {
    getA() { return 0; }
    constructor() {}
}
class B extends A {
    getB() { return 0; }
    constructor() { super(); }
}
console.log((new A()));
console.log((new A()).__proto__);
console.log((new A()).__proto__ instanceof A);
console.log((new A()).__proto__ instanceof Object);
console.log((new B()));
console.log((new B()).__proto__);
console.log((new B()).__proto__ instanceof B);
console.log((new B()).__proto__ instanceof A);

Node 14 produces:

A {}
A {}
false
true
B {}
B {}
false
true

This is wrong since (new B()).__proto__ is an instance of A. I guess the confusing part is that (new B()).__proto__.constructor is class B (which is because of https://tc39.es/ecma262/#sec-makeconstructor)

For reference, Chrome DevTools produces:

A {}
{constructor: ƒ, getA: ƒ}
false
true
B {}
A {constructor: ƒ, getB: ƒ}
false
true

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions