简体   繁体   中英

Adding console.log to every function automatically - part 2

Follow up question to the solution posted here:

Adding console.log to every function automatically

This works great for getting the name of the function called:

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);
    }
  }
}

Can you also list the arguments supplied to the function that was called?

If you read the code, you can see that fn is being called with arguments, and that is what you want in your function. So just add it to args :

withFn.apply(this, Array.from(args).concat([arguments]));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM