我目前正在构建一个更大的对象,需要更快速和更具体地进行调试/检查值/结果/返回。
现在我想到了以下几点:
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 );
},
};
这将使我能够简单地将对象变量
debug
定义为一个函数名称,并仅记录此部分。唯一的问题是:我如何获取
FunctionName
/someFunction
?附注:
console.log( arguments.callee );
给出整个函数源代码。console.log( arguments.callee.name );
返回为空。console.log( arguments.callee.toString() );
返回为空。console.log( arguments.caller );
返回undefined
。
prototype.name="Empty"
等。因此,无法直接从对象中获取它。谢谢!
true
,那么当执行myObject
的任何函数时,您希望记录控制台消息,其中包括函数名称和参数? - kubetzvar x = y, a = b;
与var x = y; var a = b;
以及var x, a; x = y; a = b;
是相同的,只是变量声明和赋值方式不同而已。JS确实很有趣 ; )。 - kubetz