Skip to content

Instantly share code, notes, and snippets.

@JosePedroDias
Created December 5, 2014 18:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JosePedroDias/a6a28f1d3315921e7632 to your computer and use it in GitHub Desktop.
Save JosePedroDias/a6a28f1d3315921e7632 to your computer and use it in GitHub Desktop.
debug function call (js)

if you want to log the call parameters for function xyz, add this is the first line of xyz:

function xyz(p1, p2) {
    debugFunctionCall('xyz', arguments);
    ...
}

then if you call

xyz(2, "stuff", {a:2});

it prints

xyz(2, "stuff", {"a":2})
function debugFunctionCall(functionName, args) {
var o = [];
o.push(functionName);
o.push('(');
for (var i = 0, I = args.length; i < I; ++i) {
o.push( JSON.stringify(args[i]) );
o.push(', ');
}
o.pop();
o.push(')');
console.log( o.join('') );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment