在此链接中的 javascript 中的承诺文档中。这个已经写完了:
使用已解决的承诺,“then”块将立即触发,但其处理程序将异步触发
// using a resolved promise, the 'then' block will be triggered instantly,
// but its handlers will be triggered asynchronously as demonstrated by the console.logs
var resolvedProm = Promise.resolve(33);
var thenProm = resolvedProm.then(function(value){
console.log("this gets called after the end of the main stack. the value
received and returned is: " + value);
return value;
});
// instantly logging the value of thenProm
console.log(thenProm);
// using setTimeout we can postpone the execution of a function to the moment
// the stack is empty
setTimeout(function(){
console.log(thenProm);
});
// logs, in order:
// Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
// "this gets called after the end of the main stack. the value received and returned is: 33"
// Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: 33}
我不太明白它所说的块将被触发但处理程序被异步触发的部分。我的问题是:
then 块是什么?它的处理程序是什么,它们有何不同?
每个触发什么?
- 当该异步触发器发生时,它毕竟被解决了
谢谢你。