我想要退回respone
。我打电话给我的第一个提醒是undefined
(这意味着它没有返回)和第二个提醒true
。
alert(checkDeviceDataNetwork());
function checkDeviceDataNetwork(){
var networkResponse;
bridge_g.callHandler('NetworkReachable',"" , function(response) {
alert(response);
networkResponse=response;
return networkResponse;
if(response=="false"){
alert("Please check the network");
}});
}
答案 0 :(得分:0)
将回调发送到函数
checkDeviceDataNetwork(function(err, message) {
// bubble error if present; check console for this one
if (err) throw err;
// otherwise alert message
alert(message);
});
function checkDeviceDataNetwork(callback){
var networkResponse;
bridge_g.callHandler('NetworkReachable',"" , function(response) {
callback(null, response);
networkResponse=response;
if(response=="false"){
callback(Error("Please check the network"));
}
return networkResponse;
});
}