I have a class having structure like :
class A {
constructor() {}
myMethod() {
console.log('in my method');
}
}
I want to make a method that will accept className
and methodName
like :
modifyClassMethod(className, methodName)
This method should wrap the whole body of methodName
specified into a callback during runtime.
So if I do,
modifyClassMethod(A, myMethod)
Now during runtime the body of myMethod of
class A should get changed to
myMethod() {
nr.recordMe('here', {
console.log('in my method').
})
}
Now when I will create a new object of A
class, then I will get modified value of myMethod
.
How can I achieve this in TS or JS ?.