永发信息网

js promise 中的then的值能直接返回出来吗

答案:1  悬赏:50  手机版
解决时间 2021-11-14 14:23
  • 提问者网友:焚苦与心
  • 2021-11-13 18:08
js promise 中的then的值能直接返回出来吗
最佳答案
  • 五星知识达人网友:第幾種人
  • 2021-11-13 19:02
then方法的实现里,确实是返回了一个新的Promise,你说的double,其实是then的第一个参数onFulfilled。
  this.then = function (onFulfilled, onRejected) {
var self = this;
return new Promise(function (resolve, reject) {
return self.done(function (result) {
if (typeof onFulfilled === 'function') {
try {
return resolve(onFulfilled(result));
} catch (ex) {
return reject(ex);
}
} else {
return resolve(result);
}
}, function (error) {
if (typeof onRejected === 'function') {
try {
return resolve(onRejected(error));
} catch (ex) {
return reject(ex);
}
} else {
return reject(error);
}
});
});
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯