Я хочу убедиться, что я не пропущу трюк; в библиотеке Kris Коваля, вы можете сделать следующее в качестве общего заявления на вылов в обещаниях:jQuery Отложенный - catch vs fail
var a, b, c, d, e, f;
readFile('fileA')
.then(function (res) {
a = res;
return readFile('fileB');
})
.then(function (res) {
b = res;
return readFile('fileC');
})
.then(function (res) {
c = res;
return readFile('fileD');
})
.then(function (res) {
d = res;
return readFile('fileE');
})
.then(function (res) {
e = res;
return readFile('fileF');
})
.then(function() {
f = res;
})
.catch(function() {
// error happened in file read *somewhere* (don't care where)
});
В отсроченных объектах JQuery, есть не catch
заявления, вместо этого, я должен сделать это:
var a, b, c, d, e, f;
readFile('fileA')
.then(function (res) {
a = res;
return readFile('fileB');
})
.fail(function() {
// error happened in file read *somewhere* (don't care where)
})
.then(function (res) {
b = res;
return readFile('fileC');
})
.fail(function() {
// error happened in file read *somewhere* (don't care where)
})
.then(function (res) {
c = res;
return readFile('fileD');
})
.fail(function() {
// error happened in file read *somewhere* (don't care where)
})
.then(function (res) {
d = res;
return readFile('fileE');
})
.fail(function() {
// error happened in file read *somewhere* (don't care where)
})
.then(function (res) {
e = res;
return readFile('fileF');
})
.fail(function() {
// error happened in file read *somewhere* (don't care where)
})
.then(function (res) {
f = res;
return readFile('fileF');
})
.fail(function() {
// error happened in file read *somewhere* (don't care where)
});
К сожалению, каждая ветка then
имеет уникальную логику. Я что-то упускаю, или вариация jQuery выше единственного способа достижения эквивалента в библиотеке Kris Kowal q
?
ли вам попробуйте цепочку 'then()' и используя единственный '.fail();' в конце? он должен работать. –
Это типичный вопрос для Себастьяна, им все еще не уверен, что вы можете заменить улов неудачей –
@ A.Wolff ах .. Кто Sebastien ..? другой волк ..? ._. –