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

Access to callee in arrow functions

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

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

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

简短的回答是

事实上,箭头函数不会绑定它自己的 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 "feature" 是一个非常糟糕的主意.