caller

废弃的 arguments.caller 属性原先用在函数执行的时候调用自身。本属性已被移除且不再有用。

描述

arguments.caller 已经不可使用了,但是你还可以使用 Function.caller

function whoCalled() {
   if (whoCalled.caller == null)
      console.log('I was called from the global scope.');
   else
      console.log(whoCalled.caller + ' called me!');
}

示例

下例演示了arguments.caller属性的作用.

function whoCalled() {
   if (arguments.caller == null)
      console.log('该函数在全局作用域内被调用.');
   else
      console.log(arguments.caller + '调用了我!');
}

规范

无相关标准。JavaScript 1.1 实现,bug 7224 移除 caller,因为潜在的不安全性。

浏览器支持

Update compatibility data on GitHub
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
caller
Deprecated Non-standard
Chrome No support No Edge No support No Firefox No support No IE No support 3 — 9 Opera No support No Safari No support No WebView Android No support No Chrome Android No support No Firefox Android No support No Opera Android No support No Safari iOS No support No Samsung Internet Android No support No nodejs No support No

Legend

No support  
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.

相关链接