废弃的 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,因为潜在的不安全性。
浏览器支持
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out
https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
caller
|
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.