Tag: 对讲

如何在Javascript中支持2种types的callback

在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 }); 我的问题是:如何通过funcrtion(err,d)或只是function(data)知道intercom 。 我检查了源代码,发现他们使用bluebird库。 蓝鸟如何做呢? 我希望我的function也能做到这一点。 换一种说法: function myFunction(data,callback){ if (callbackListenToErrArgument(callback)) callback(null,data) else callback(data) } 如何实现callbackListenToErrArgument函数?