Coffeescript, how would I write this example as a queue, especially a loop?

I am trying to give some examples under my belt about how you will do something different in CoffeeScript for JavaScript. In this example of queue functions, I am confused about how you handle this in 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())();   
    }

Especially how to rewrite this in CoffeeScript?

while (Array.length > 0) {
    (Array.shift())(); 
+3
source share
2 answers
f1 = (completeCallback) ->
  console.log('Waiting...')
  completeCallback()

funcs = [ f1, f2, f3 ]

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

next()
+3
source
fun1 = -> alert 'Hello Fun1'
fun2 = -> alert 'Hello Fun2'

funqueue = [fun1, fun2]

el() for el in funqueue
+4
source

Source: https://habr.com/ru/post/1775879/


All Articles