JScript 8.0 中文手册| 首页 | asp之家
caller 属性

返回一个对函数的引用,该函数调用了当前函数。

function.caller 
参数
function

必选。当前正在执行的 Function 对象的名称。

备注

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

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

Note注意

caller 属性在以快速模式(JScript 的默认模式)运行时不可用。若要从命令行编译使用 caller 属性的程序,必须使用 /fast- 关闭快速选项。由于线程处理问题,在 ASP.NET 中关闭快速选项是不安全的。

示例

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

function callLevel(){
   if (callLevel.caller == null)
      print("callLevel was called from the top level.");
   else {
      print("callLevel was called by:");
      print(callLevel.caller);
   }
}
function testCall() {
   callLevel()
}
// Call callLevel directly.
callLevel();
// Call callLevel indirectly.
testCall();

当使用 /fast- 选项编译该程序后,该程序的输出为:

callLevel was called from the top level.
callLevel was called by:
function testCall() {
   callLevel()
}
要求

版本 2

请参见

参考

function 语句