Skip to content

Instantly share code, notes, and snippets.

@vhsu
Last active July 8, 2018 06:54
Show Gist options
  • Save vhsu/357b8463c3a5a89b4942407e8cbf8fce to your computer and use it in GitHub Desktop.
Save vhsu/357b8463c3a5a89b4942407e8cbf8fce to your computer and use it in GitHub Desktop.
Javascript debugging : Add console logs in functions in the global namespace
//Author Wayne Burkett
//https://stackoverflow.com/questions/5033836/adding-console-log-to-every-function-automatically#5034657
//Add console log to all existing function existing in 5he global namespace at the time of execution
function augment(withFn) {
var name, fn;
for (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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment