据我了解,promise 是可以 resolve() 或 reject() 的东西,但我惊讶地发现 promise 中的代码在调用 resolve 或 reject 后继续执行。
我认为 resolve 或 reject 是 exit 或 return 的异步友好版本,它将停止所有立即执行的函数。
有人可以解释为什么以下示例有时会在解析调用后显示 console.log 背后的想法:
var call = function() {
return new Promise(function(resolve, reject) {
resolve();
console.log("Doing more stuff, should not be visible after a resolve!");
});
};
call().then(function() {
console.log("resolved");
});