我已经知道 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)它自己的 this
、arguments
、super
...,它们旨在提供一个如果我们检查 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/