drkoss
drkoss

Reputation: 79

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?

Upvotes: 0

Views: 157

Answers (1)

juvian
juvian

Reputation: 16068

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

Upvotes: 1

Related Questions