How can I get the names of the methods in a constructor of a class?

From within constructor:


class Example {
    
    constructor(){
        var proto = Object.getPrototypeOf(this);
        var methods = Object.getOwnPropertyNames(proto);
        methods.shift();
        console.log(methods);
    }

    method1(){}
    method2(){}

}

var x = new Example();
// (2) ["method1", "method2"]
1 Like