【问题标题】:Coffeescript's Q.defer() then's call backCoffeescript 的 Q.defer() 然后回调
【发布时间】:2017-02-22 22:02:30
【问题描述】:

见过

defereed.then (arg) =>
    function body

还有

deferred.then ( 
    (arg) =>
        function  body
)

有人能解释一下区别吗?

这是来自https://github.com/gwomacks/php-debug/blob/master/lib/engines/dbgp/dbgp-instance.coffee

【问题讨论】:

  • 如果你提到this,那只是奇怪的缩进。
  • 前一种形式在该文件的上半部分占主导地位。后者开始出现在另一半。

标签: coffeescript promise q deferred


【解决方案1】:

没有区别。 Coffeescript 中的括号是可选的:

如果您传递参数,则无需使用括号来调用函数。隐式调用向前换行到行或块表达式的末尾。

console.log sys.inspect object → console.log(sys.inspect(object));

【讨论】:

    【解决方案2】:

    这没有任何区别。下面的代码证明了这一点。

    doubleValue = (value) ->
      deferred = q.defer()
      deferred.resolve value * 2
      deferred.promise
    
    doubleValue(3).then (result) =>
      console.log  result
    
    doubleValue(4).then ((result) =>
      console.log  result
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-12
      • 1970-01-01
      • 2013-07-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多