Reputation: 23
I need to implement a listener which will perform a certain action if FunctionA is called on the page at any time (during or after page load).
Or in other words I need to listen for an execution of FunctionA.
How to achieve this?
Thank you.
Upvotes: 0
Views: 3183
Reputation: 4039
You can make a self-wrapping function the following way.
var _ = functionA; // This variable needs to be always available to functionA
functionA = function(arg1, arg2) {
_(arg1, arg2);
alert("functionA was caled!");
}
Change the alert part to you event
This way everytime anyone calls this function you get notified.
Upvotes: 1
Reputation: 5190
if you are sure function A has synchronous code you can wrap it in a function of yours and track its execution that way
function _A(){
A.call(undefined, ...arguments);
// A has finished execution
}
if the code is asynchronous then the issue is more complicated
Upvotes: 0
Reputation: 281
You can call a Function at the end/start of your FunctionA:
function FunctionA(){
/* Your method implementation here */
FunctionB();
}
Upvotes: 0