caller 属性(函数)(JavaScript)

转载:http://msdn.microsoft.com/zh-cn/library/7t96kt3h(v=vs.94).aspx

 

获取调用当前函数的函数。

functionName.caller

 

备注

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

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

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

下面的示例阐释了 caller 属性的用法:

 1 function CallLevel(){
 2    if (CallLevel.caller == null)
 3       return("CallLevel was called from the top level.");
 4    else
 5       return("CallLevel was called by another function.");
 6 }
 7 
 8 document.write(CallLevel());
 9 
10 // Output: CallLevel was called from the top level.

 

要求

在以下文档模式中受支持:Quirks、Internet Explorer 6 标准模式、Internet Explorer 7 标准模式、Internet Explorer 8 标准模式、Internet Explorer 9 标准模式、Internet Explorer 10 标准模式和 Internet Explorer 11 标准模式。此外,也在应用商店应用(Windows 8 和 Windows Phone 8.1)中受支持。

 

posted @ 2014-08-26 16:17  johnnylion  阅读(259)  评论(0编辑  收藏  举报