0

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?

Community
  • 1
  • 1
drkoss
  • 79
  • 1
  • 6

1 Answers1

1

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]));
juvian
  • 15,875
  • 2
  • 37
  • 38
  • Aha -thanks. I knew the arguments were there but wasn't concatenating. Cheers. For any who are doing this in Max/MSP - Array.from(args) is not available - so use arrayfromargs(args) instead. – drkoss Apr 11 '17 at 19:35