【发布时间】:2014-11-26 07:06:24
【问题描述】:
在fileA中,我可以做
@someAPI = SomeAPI()
@someAPI.getUser '123'
然后在文件B中
class SomeAPI
constructor: (options = {}) ->
unless @ instanceof SomeAPI
return new SomeAPI(options)
getUser: (id) ->
someAPI.get 'users/show', { 'id': id }, (err, data, res) ->
if data
console.log data.name
但是有什么方法可以返回回调,所以我可以在 fileA 中进行处理吗?
fileA 伪代码
...
processUser: (id) ->
@someAPI.getUser id, (err, data, res) ->
if data
console.log data.name
processUser '123'
fileB 伪代码
...
getUser: (id) ->
return someAPI.get 'users/show', { 'id': id }, (err, data, res)
这适用于 Meteor 应用,其中 fileA 是应用的一部分,fileB 是包的一部分。
【问题讨论】:
-
这是在客户端还是服务器上?
标签: javascript meteor coffeescript