从Coffeescript中的嵌套函数获取值
我想从另一个函数(匿名函数)获取结果,但我不知道如何获取,因为我的结果函数是嵌套函数。也许我得用回拨电话? 这是我的代码:从Coffeescript中的嵌套函数获取值,coffeescript,nested,anonymous-function,Coffeescript,Nested,Anonymous Function,我想从另一个函数(匿名函数)获取结果,但我不知道如何获取,因为我的结果函数是嵌套函数。也许我得用回拨电话? 这是我的代码: render: -> console.log @getCommunities() return this getCommunities: -> dpd.communities.get (result, err) -> return console.log(err) if err result g
render: ->
console.log @getCommunities()
return this
getCommunities: ->
dpd.communities.get (result, err) ->
return console.log(err) if err
result
getCommunities()始终返回“未定义”
有人知道如何解决这个问题吗
谢谢,
罗扬这个怎么样
render: ->
@getCommunities (err, result) ->
if err then throw err
console.log result
return this
getCommunities: (callback) ->
dpd.communities.get (result, err) ->
return console.log(err) if err
callback(null, result)
仅供参考,最好将err
作为第一个参数传递给节点中的回调,假设这实际上是节点…只是通过err回调进行猜测