javascript Times X JS功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Times X JS功能相关的知识,希望对你有一定的参考价值。

// A function to repeat whatever you feed it an x amount of time
// https://stackoverflow.com/a/30452949/4474075
const times = x => f => {
  if (x > 0) {
    f()
    times (x - 1) (f)
  }
}

// use it
times (3) (() => console.log('hi'))

// or define intermediate functions for reuse
let twice = times (2)

// twice the power !
twice (() => console.log('double vision'))

以上是关于javascript Times X JS功能的主要内容,如果未能解决你的问题,请参考以下文章