Last active
July 8, 2018 06:54
-
-
Save vhsu/357b8463c3a5a89b4942407e8cbf8fce to your computer and use it in GitHub Desktop.
Javascript debugging : Add console logs in functions in the global namespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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