javascript的caller方法

function CallLevel(){
   if (CallLevel.caller == null)
      return("CallLevel was called from the top level.");
   else
      return("CallLevel was called by another function.");
}

document.write(CallLevel());

// Output: CallLevel was called from the top level.函数

 

 

functionName 对象是任何正在执行的函数的名称。spa

caller 属性只有当函数正在执行时才被定义。  若是函数是从 JavaScript 程序的顶层调用的,则 caller 包含 null  对象

若是在字符串上下文中使用 caller 属性,则其结果和 functionName.toString 相同,也就是说,将显示函数的反编译文本。ip

相关文章
相关标签/搜索