admin管理员组文章数量:1289928
I already know that arrow functions do not have an arguments variable bound to them. This is fine, for the most part, because I can simply use the ...
operator and expand the list of arguments into an array.
But arguments
has a special property arguments.callee
(a reference to the function currently executing), which is extremely useful for recursion or for unbinding listeners. How do I access that value from an arrow function? Is it possible?
I already know that arrow functions do not have an arguments variable bound to them. This is fine, for the most part, because I can simply use the ...
operator and expand the list of arguments into an array.
But arguments
has a special property arguments.callee
(a reference to the function currently executing), which is extremely useful for recursion or for unbinding listeners. How do I access that value from an arrow function? Is it possible?
-
3
The
arguments.callee
"feature" was a pretty bad idea. If you need to refer to the function, don't use an arrow function and make a named function instead. – Pointy Commented Jun 21, 2017 at 12:45 - ^ That and stackoverflow./questions/30935336/… – enapupe Commented Jun 21, 2017 at 12:46
- stackoverflow./questions/103598/… – epascarello Commented Jun 21, 2017 at 12:47
- 1 Arrow functions were meant to be the lambdas of JS, a lambda is anonymous and it's a bit tricky to call them back without storing them in a variable. – Vivick Commented Jun 21, 2017 at 12:48
- @enapupe No kidding. I'm aware of the syntax changes. I was more wondering if something was hidden that I didn't know about. – cwallenpoole Commented Jun 21, 2017 at 14:08
1 Answer
Reset to default 11How do I access that value from an arrow function? Is it possible?
Short answer is No.
In fact an arrow function don't bind its own this
, arguments
, super
..., they were meant to provide a shorter syntax with less details, if we check the MDN Reference for Arrow functions we can see that:
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.
So you won't be able to get a reference to the function itself with Arrow functions, and as stated in ments arguments.callee "feature" was a pretty bad idea.
本文标签: javascriptAccess to callee in arrow functionsStack Overflow
版权声明:本文标题:javascript - Access to callee in arrow functions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741481129a2381179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论