observe-function
Observe when a function is called and assign callbacks before and after the function is called.
Install
$ npm install --save observe-function
Usage
var observeFunction = ; var { console; return arg1 + arg2;}; //Simply wrap the function you want to observevar observer = ; //assign callback to be called before function executesobserver; //... and after it executesobserver; //call the observer just as you would the regular functionvar three = ;//=>I am called before//=>I am observed//=>I am called after console;//=> 3
API
observeFunction(anyFunction)
Assigns the function to be observed. Returns a function that can be called just like the provided function.
observer.before(callback)
Assigns a callback to be called before the function is called. An observer can be assigned multiple "before" callbacks.
observer.after(callback)
Assigns a callback to be called after the function is called. An observer can be assigned multiple "after" callbacks.
observer.remove.before(callback)
Removes the specified callback from the list of "before" callbacks
observer.remove.after(callback)
Removes the specified callback from the list of "after" callbacks
observer.reset.before()
Removes all callbacks from the list of "before" callbacks
observer.reset.after()
Removes all callbacks from the list of "after" callbacks
observer.reset.all()
Removes all "before" and "after" callbacks