废弃的 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
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Basic support
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support NoIE No support ? — 9Opera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs 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.

相关链接

文档标签和贡献者

此页面的贡献者: fscholz, Ende93, teoli, ziyunfei
最后编辑者: fscholz,