如何在iced coffee script
使用return
and中返回几个值autocb
?
没有autocb
我可以做到:
func = (cb)=>
cb returnVal1, returnVal2
如何使用autocb
?这段代码...
func = (autocb)=>
return returnVal1, returnVal2
...抛出错误:
SyntaxError: unexpected ,
如何在iced coffee script
使用return
and中返回几个值autocb
?
没有autocb
我可以做到:
func = (cb)=>
cb returnVal1, returnVal2
如何使用autocb
?这段代码...
func = (autocb)=>
return returnVal1, returnVal2
...抛出错误:
SyntaxError: unexpected ,
您收到错误是因为您在 JavaScript 中不能返回多个值。您可以将这两个值包装在一个数组中并在调用后对其进行解构...
func = (autocb)=>
return [returnVal1, returnVal2]
await func defer(returnVals)
[returnVal1, returnVal2] = returnVals
...但您可能应该只使用您的第一个示例。autocb
是简单的语法糖(一个参数而不是一行),并且完全不需要使用 IcedCoffeeScript。
解构将按照此处所述进行:https ://github.com/maxtaco/coffee-script/issues/29
func = (thing, autocb) ->
thing1 = doSomething(thing)
thing2 = doSomethingElse(thing)
{thing1, thing2}
await funct thing, defer {thing1, thing2}
console.log "#{thing1} and #{thing2}"