JavaScript ES6: Test for arrow function, built-in function, regular function?

后端 未结 10 751
遇见更好的自我
遇见更好的自我 2020-11-27 06:16

Is there an elegant way to tell Harmony\'s slim arrow functions apart from regular functions and built-in functions?

The Harmony wiki states that:

10条回答
  •  孤街浪徒
    2020-11-27 06:27

    As far as I can tell this should work:

    All non-arrow functions when converted to String START with 'function '. Arrow functions don't.

    Trying to test for the presence of '=>' is not a reliable way to test whether the function is an arrow or not because any non-arrow function can contain arrow-functions inside them and thus the '=>' can be present in their source-code.

提交回复
热议问题