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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -