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 - Feed FileReader from server side files -

java - How to create your own button and Use it with Scene Builder for javafx -

c++ - Drawing a circle in directx 9 -