Discuss
/
JavaScript
/
最大的疑问是.then()与.resolve()谁先执行?
最大的疑问是.then()与.resolve()谁先执行?
Topic source我是这么理解的: 执行了resolve只是给then发送了一个信号 在设置then之后,promise object会检查收到的信号 如果收到信号了 那么.then就直接执行 如果没有收到信号 .then就等待
真正异步执行的是.then()的参数函数
在new Promise(function (resolve, reject) {})中的function是同步执行的
你可以试一下这个
var test = new Promise(function(res, rej){
alert('Now, we are in executor...');
res('Send a signal to .then()');
});
alert('we have just create the Promise object -- test!');
test.then(function(r){
alert('We just receive the signal from res(), which says\n'+ '"'+r+'"');
});
- 1
乌鸦与水
如果.then()执行较慢或是不执行,在new Promise(function (resolve, reject) {})中的resolve()执行不不执行,此时的resolve有没有指向处理函数?有些不明白。