javascript - Adding console.log to every function automatically -


is there way make function output console.log statement when it's called registering global hook somewhere (that is, without modifying actual function itself) or via other means?

here's way augment functions in global namespace function of choice:

function augment(withfn) {     var name, fn;     (name in window) {         fn = window[name];         if (typeof fn === 'function') {             window[name] = (function(name, fn) {                 var args = arguments;                 return function() {                     withfn.apply(this, args);                     return fn.apply(this, arguments);                  }             })(name, fn);         }     } }  augment(function(name, fn) {     console.log("calling " + name); }); 

one down side no functions created after calling augment have additional behavior.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -