Coffeescript,我将如何编写这个排队函数示例,尤其是循环?
我正在尝试获取一些示例,说明如何在 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())();
I'm trying to get some examples under my belt of how you would do something differently in CoffeeScript to JavaScript. In this example of queuing functions I'm confused at how you would do 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 would I rewrite this in CoffeeScript?
while (Array.length > 0) {
(Array.shift())();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)