ES6 immediately invoke recursive arrow function

前端 未结 3 1489
-上瘾入骨i
-上瘾入骨i 2021-02-13 13:53

This is my current code:

const fn = parameter => {
    // if, else ...
    fn(X);
};
fn(0);

Now, I can\'t use this approach as I need to cal

3条回答
  •  猫巷女王i
    2021-02-13 13:54

    JavaScript provides a great solution for recursive functions: named function expressions. Hence I would recommend to use that instead of an arrow function:

    (function fn(parameter) {
      // if, else ...
      fn(x);
    })(0);
    

提交回复
热议问题