For debugging purposes, I was wondering if there's some way in which I can create a piece of code to run whenever a javascript function is called - like adding something to Function.prototype or Function.constructor etc.
Asked
Active
Viewed 159 times
0
-
2check this out: http://stackoverflow.com/questions/5226550/can-i-override-the-javascript-function-object-to-log-all-function-calls – Cristi Pufu Jul 28 '14 at 09:45
1 Answers
0
You could use a "decorator-like".
Something as simple as executing
var yourFunction = function { // do stuff };
var yourSecondFunction = function { // do stuff };
var myDecorator = function( callback )
{
// do your stuff
// ...
// then execute function
callback();
};
// usage
myDecorator( yourFunction );
myDecorator( yourSecondFunction );
I don't think overwriting the prototype of Function
is a good idea.

Nicolas Brugneaux
- 353
- 2
- 8