Is there a way to make any function output a console.log statement when it's called by registering a global hook somewhere (that is, without modifying the actual function itself) or via some other means?
log() with Examples. The console. log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.
It's a function call. It goes to the call stack.
Type it and press Ctrl+Alt+W + W . Another way to console. log your variables is to simply place your mouse cursor on them and then wrap them on the line below with Ctrl+Alt+W + Down or the line above with Ctrl+Alt+W + Up .
"So what?" you probably asked? - This is important part, because console. log() is asynchronous. All asynchronous functions come to Event Table in terms of Event Loop.
Here's a way to augment all functions in the global namespace with the function of your choice:
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); });
One down side is that no functions created after calling augment
will have the additional behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With