【发布时间】:2016-05-18 04:31:10
【问题描述】:
在intercom-client github 我看到了这段代码:
client.users.list(function (d) { // d is the response from the server }); // Or client.users.list(function (err, d) { // err is an error response object, or null // d is a successful response object, or null });
我的问题是:intercom 如何知道我是通过funcrtion(err,d) 还是只是通过function(data)。
我检查了源代码,发现他们使用bluebird 库。蓝鸟是怎么做到的?
我希望我的函数也能做到这一点。
换句话说:
function myFunction(data,callback){
if (callbackListenToErrArgument(callback))
callback(null,data)
else
callback(data)
}
callbackListenToErrArgument功能如何实现?
【问题讨论】:
标签: javascript node.js bluebird intercom