How do I write an arrow function in ES6 recursively?

后端 未结 12 919
南旧
南旧 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:22

    You can assign your function to a variable inside an iife

    var countdown = f=>(f=a=>{
      console.log(a)
      if(a>0) f(--a)
    })()
    
    countdown(3)
    
    //3
    //2
    //1
    //0
    

提交回复
热议问题