caller 属性 (Function)
获取调用当前函数的函数。
语法
functionName.caller
备注
functionName对象是任何正在执行的函数的名称。
caller属性只有当函数正在执行时才被定义。如果函数是从JavaScript程序的顶层调用的,则caller包含null。
如果在字符串上下文中使用caller属性,则其结果和functionName.toString相同,也就是说,将显示函数的反编译文本。
下面的示例阐释了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.
必备条件
在以下文档模式中受支持:怪异模式、Internet Explorer 6标准模式、Internet Explorer 7标准模式、Internet Explorer 8标准模式、Internet Explorer 9标准模式、Internet Explorer 10标准模式、Internet Explorer 11标准模式。应用商店应用(Windows 8和Windows Phone 8.1)中也受支持。请参阅版本信息。