Is there a way to determine if a function is a method of a certain class?
I have a class A
with a method doesMethodBelongHere
, that takes a function as an argument method
. I want to determine that method
is an actual method of A
.
class A {
methodA() {
console.log('method of A');
}
doesMethodBelongHere(method) {
// it should return true if `method` argument is a method of A
return Object.values(this).includes(method);
}
}
const a = new A();
console.log(a.doesMethodBelongHere(a.methodA)); // should return true