我在我的网站上使用了 Promise(仍在学习),我想知道这之间是否有区别:
return promise
.then(ctxTransport.getTransportById(idTran, transport))
.then(checkLocking)
.fail(somethingWrong);
和这个:
return promise
.then(function () { return ctxTransport.getTransportById(idTran, transport); })
.then(function () { return checkLocking(); })
.fail(somethingWrong);
在第一次实现时,有时我会出错。
var getTransportById = function (transportId, transportObservable, forceRemote) {
// Input: transportId: the id of the transport to retrieve
// Input: forceRemote: boolean to force the fetch from server
// Output: transportObservable: an observable filled with the transport
...
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
function querySucceeded(data) {
transportObservable(data.results[0]);
}
};
function checkLocking() {
var now = new Date();
transport().lockedById(5);
transport().lockedTime(now);
return ctxTransport.saveChanges(SILENTSAVE);
}
function somethingWrong(error) {
var msg = 'Error retreiving data. ' + error.message;
logError(msg, error);
throw error;
}
谢谢。