I want to inject code in javascript, for debugging purposes, within every one of my method prototypes in javascript. This example shows one class only, but assume I have hundreds of classes and each class has dozens of methods. This mechanism should perform at prototype level without the need to specify each class/method name.
function MyClass1() {
this.attrib = "ABC";
}
MyClass1.prototype.myMethod = function() {
alert("first row"); // <---- THE INJECTION SHOULD OCCUR BEFORE THIS LINE OF CODE
}
The idea is to dynamically inject some code before the first row of myMethod(), during the first loading/execution of the javascript code. Such as:
MyClass1.prototype.myMethod = function() {
alert("I was injected dynamically");
alert("first row");
}
So for every other Class and Method, the same should happen. Is this achievable using the Function.prototype approach ?