Share via


caller 屬性

更新:2007 年 11 月

傳回函式的參考,此函式會叫用目前的函式。

function.caller 

引數

  • function
    必要項。目前正在執行的 Function 物件名稱。

備註

caller 屬性只會定義給正在執行的函式。如果從 JScript 程式的頂層呼叫函式,則 caller 會包含 null。

如果 caller 屬性使用於字串內容中,則其結果與 functionName.toString 相同,也就是說,會顯示出函式的解譯文字。

注意事項:

當以 JScript 預設的快速模式執行時,無法使用 caller 屬性。如果從命令列來編譯使用 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 版

套用至:

arguments 物件| Function 物件

請參閱

參考

function 陳述式