The best way to explain my problem is through the below code:
class SomeClass {
SomeMethod() {
console.log("SomeMethod was called");
}
}
var someInstance = new SomeClass();
// The below expression expected to return True but is returns False
console.log(
someInstance.hasOwnProperty("SomeMethod")
);
// The below expression is expected to include SomeMethod in the return list, but it doesn't
console.log(
Object.keys(someInstance)
);
// The below expression is expected to include SomeMethod in the return list, but it doesn't
console.log(
Object.getOwnPropertyNames(someInstance)
);
// The below expression works fine which confrms that the function exists.
someInstance.SomeMethod();
I would expect Object.keys()
or Object.getOwnPropertyNames()
to return all properties including methods defined in the class definition of the class from which this object was constructed but for some reason neither does.
If neither of these functions works in such a scenario then how can I list all methods of a class instance?