0
我打電話function
,並在node
function
的內部輸入callback
。 function
發射並完成其任務,但我無法弄清楚如何從callback
中檢索response
。處理來自回撥函數的響應
foo() {
merchant.createCustomerProfile(cardNumber, expDate, email, id, function callback(){
// How do I retrieve the response from the callback?
// console.log(callback);
});
//so I can pass it out here and use it
}
的function
與callback
實際上returns
callback
。它看起來像這樣,
function createCustomerProfile(cardNumber, expDate, email, id, callback) {
ctrl.execute(function(){
var apiResponse = ctrl.getResponse();
var response = new ApiContracts.CreateCustomerProfileResponse(apiResponse);
if(response != null)
{
if(response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK)
{
console.log('Successfully created a customer profile with id: ' + response.getCustomerProfileId());
}
else
{
console.log('Result Code: ' + response.getMessages().getResultCode());
console.log('Error Code: ' + response.getMessages().getMessage()[0].getCode());
console.log('Error message: ' + response.getMessages().getMessage()[0].getText());
}
}
else
{
console.log('Null response received');
}
callback(response);
});
}
我試圖獲得resultCode
,應在回調函數的響應。