Skip to content

Multiple Call to super in child class constructor does not give any error #5317

Closed
@zeeshanhanif

Description

@zeeshanhanif

A call to super multiple times in Child class' constructor does not give any error, is it expected behavior? Dose it initiate multiple parent objects?

class E {
    name:string;
    constructor(theName: string,age:number) { 
        this.name = theName; 
        console.log("E constrcutor");
    }
    displayName():void {
        console.log(" Name = " + this.name);
    }
}
class F extends E {
    name:string;
    constructor(theName: string) {
        this.name = theName; 
        console.log("F constrcutor");
        super(theName,4);
        super("Hello",5); // No error here 
    }
}
let e: E = new E("E",1);
let f: F = new F("F");
f.displayName(); // return "Hello"

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions