从一道前端面试题看JavaScript的核心运行机制

Posted by fengmiaosen on 2017-03-15
1
2
3
4
5
6
7
8
9
10
11
12
13
setTimeout(function() {
console.log(1)
}, 0);
new Promise(function executor(resolve) {
console.log(2);
for( var i=0 ; i<10000 ; i++ ) {
i == 9999 && resolve();
}
console.log(3);
}).then(function() {
console.log(4);
});
console.log(5);

运行结果:

1
2
3
4
5
2
3
5
4
1

参考资料