Is there a way to name arrow functions in javascript?

前端 未结 1 498
梦如初夏
梦如初夏 2021-01-11 15:41

I\'m using arrow functions in an app and sometimes there is the need to get a reference to the function itself. For normal javascript functions, I can just name them and use

相关标签:
1条回答
  • 2021-01-11 16:19

    Is there a way to name arrow functions so that a reference can be used from within

    Not unless you assign it to a variable. For example:

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

    For arrow functions, I'm currently using arguments.callee

    arguments are not supported by arrow functions. TS currently incorrectly allows you to use them. This will be an error in the next version of typescript. This is to keep typescript arrow functions compatible with the JS Language Specification.

    For your use case I would just use a function

    0 讨论(0)
提交回复
热议问题