Is there any way to name arrow functions in javascript?

I use the arrow functions in the application, and sometimes it becomes necessary to get a link to the function itself. For regular javascript functions, I can just name them and use the name from the inside. For arrow functions, I use arguments.callee . Is there a way to name arrow functions so that I can use the link from the inside?

Code example

 //typescript private evaluateIf(expr: parserModule.IIfExpression, callback: IEnvCallback) { this.evaluate(expr.condition, proceed=> { guard(arguments.callee, arguments, this); if (proceed !== false) this.evaluate(expr.then, callback); else if (expr.else) this.evaluate(expr.else, callback); else callback(false); }); } //javascript Environment.prototype.evaluateIf = function (expr, callback) { var _this = this; this.evaluate(expr.condition, function (proceed) { guard(arguments.callee, arguments, _this); if (proceed !== false) _this.evaluate(expr.then, callback); else if (expr.else) _this.evaluate(expr.else, callback); else callback(false); }); }; 

What I decided after help, because the arguments may not be forever

 private evaluateIf(expr: parserModule.IIfExpression, callback: IEnvCallback) { var fn; this.evaluate(expr.condition, fn = proceed=> { guard(fn, [proceed], this); if (proceed !== false) this.evaluate(expr.then, callback); else if (expr.else) this.evaluate(expr.else, callback); else callback(false); }); } 
+5
source share
1 answer

Is there a way to name arrow functions so that the link can be used from

Not unless you assigned it to a variable. For instance:

 var foo = () => { console.log(foo); } 

For arrow functions, I am currently using arguments.callee

arguments not supported by arrow functions. TS is currently incorrectly allowing you to use them. This will be a bug in the next version of typescript. This means that the typescript arrow functions are compatible with the JS Language Specification .

For your use case, I would just use function

+9
source

Source: https://habr.com/ru/post/1216145/


All Articles