I'm currently building a bigger object and need to get faster and more specific with debugging/inspecting values/results/returns.
Now I thought about the following:
var myObject = {
whatever: null,
whereever: null,
debug: false,
someFunction: function( arg ) {
// General - would output *all* logs for all object functions.
// if ( true === myObject.debug )
// console.log( 'FunctionNameHere', arg );
// More specific - would output *only* the log for the currently targeted function
if ( 'FunctionName' === myObject.debug )
console.log( 'FunctionNameHere', arg );
},
};
This would allow me to simply define the object var debug as one function name and only log this part.
The only problem is: How would I obtain the FunctionName/someFunction?
Sidenotes:
console.log( arguments.callee );gives me the whole function source.console.log( arguments.callee.name );returns empty.console.log( arguments.callee.toString() );returns emptyconsole.log( arguments.caller );returnsundefined
If I take a look into the log of the whole object, I see prototype.name="Empty" and such. So no chance to get it directly out of the object.
Thanks!
truethen you want to log console a message with function name + arguments when any ofmyObjectfunctions is executed?debugto the function name, then only thelogof the equally named fn should trigger. This would allow me to build debug into each function and only trigger it, when needed/specified.var x = y, a = b;is same asvar x = y; var a = b;which is same asvar x, a; x = y; a = b;. Just variable declaration and assignment. And JS is definitely interesting ;).