Tag: 短路

在Promise返回函数中find第一个成功

给定一些function,返回承诺: function foo(arg) { return new Promise(function(resolve, reject) { if (stuff(arg)) { resolve('result from foo'); } else { resolve(null); } }); ); // … maybe more of these functions … function bar(arg) { return new Promise(function(resolve, reject) { if (otherStuff(arg)) { resolve('result from bar'); } else { resolve(null); } }); ); 我们怎样才能以串行方式迭代函数,在第一个函数返回一个非空值之后短路呢? [ foo, // […]