javascript - 在箭头函数中访问被调用者

标签 javascript arrow-functions

我已经知道 arrow functions do not have an arguments variable bound to them.在大多数情况下,这很好,因为我可以简单地使用 ... 运算符并将参数列表扩展到一个数组中。

但是 arguments 有一个特殊的属性 arguments.callee(对当前正在执行的函数的引用),这对于递归或解除绑定(bind)监听器非常有用。如何从箭头函数访问该值?可能吗?

最佳答案

How do I access that value from an arrow function? Is it possible?

简短的回答是

事实上,箭头函数不会绑定(bind)它自己的 thisargumentssuper ...,它们旨在提供一个如果我们检查 MDN Reference for Arrow functions,语法更短,细节更少我们可以看到:

An arrow function expression has a shorter syntax than a function expression and does not bind its own this, arguments, super, or new.target. These function expressions are best suited for non-method functions, and they cannot be used as constructors.

因此,您将无法使用箭头函数获得对函数本身的引用,正如评论中所述,arguments.callee“功能”是一个非常糟糕的主意

关于javascript - 在箭头函数中访问被调用者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44676474/

相关文章:

javascript - 如何使用箭头函数

javascript - javascript中箭头函数的流程?

javascript - Es6 React 箭头函数行为

javascript - 确定给定数字是否为 2 的幂的最佳方法是什么?

javascript - 为什么箭头函数必须声明在调用函数之上

javascript - 是数据:image/png;base64 the only base64 encoding for the img tag?

javascript - 通过使用事件监听器而不是内联 onclick 或 jquery 更改带有按钮的 div 的颜色

javascript - 带方括号的箭头函数?

javascript - 如何将变量从 MySQL 传递到 SWF

javascript - 使用下划线检查数组是否包含两个值之一