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

c# - IMAP GMAIL getting folder list problem -

PHP proxy to get XML: problem with URL arguments -