我正在尝试列举一些示例,说明您如何在CoffeeScript和JavaScript中做一些不同的事情。在此排队函数示例中,我对如何在CoffeeScript中处理此问题感到困惑

    wrapFunction = (fn, context, params) ->
            return ->
                fn.apply(context, params)

    sayStuff = (str) ->
        alert(str)


    fun1 = wrapFunction(sayStuff, this, ['Hello Fun1'])
    fun2 = wrapFunction(sayStuff, this, ['Hello Fun2'])

    funqueue = []
    funqueue.push(fun1)
    funqueue.push(fun2)

    while (funqueue.length > 0) {
        (funqueue.shift())();
    }

特别是我该如何在CoffeeScript中重写它?
while (Array.length > 0) {
    (Array.shift())();

最佳答案

f1 = (completeCallback) ->
  console.log('Waiting...')
  completeCallback()

funcs = [ f1, f2, f3 ]

next = ->
  if funcs.length > 0
    k = funcs.shift()
    k(next)

next()

10-01 16:30