Coffeescript 的 Q.defer() 然后回调

Coffeescript's Q.defer() then's call back

我看过

defereed.then (arg) =>
    function body

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

谁能解释一下区别?

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

没有区别。在 Coffeescript:

中括号是可选的

You don't need to use parentheses to invoke a function if you're passing arguments. The implicit call wraps forward to the end of the line or block expression.

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

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

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
)