How do I write an arrow function in ES6 recursively?

后端 未结 12 937
南旧
南旧 2020-12-08 06:36

Arrow functions in ES6 do not have an arguments property and therefore arguments.callee will not work and would anyway not work in strict mode even

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 07:03

    It looks like you can assign arrow functions to a variable and use it to call the function recursively.

    var complex = (a, b) => {
        if (a > b) {
            return a;
        } else {
            complex(a, b);
        }
    };
    

提交回复
热议问题