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?
An arrow function expression is an anonymous function expression written with the “fat arrow” syntax ( => ). Like traditional function expressions, arrow functions are not hoisted, and so you cannot call them before you declare them. They are also always anonymous—there is no way to name an arrow function.
By using arrow functions, we avoid having to type the function keyword, return keyword (it's implicit in arrow functions), and curly brackets.
It's a new feature that introduced in ES6 and is called arrow function. The left part denotes the input of a function and the right part the output of that function.
How 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 comments arguments.callee "feature" was a pretty bad idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With