赞
踩
console.log(1)
setTimeout(
function() {
console.log(2)
},
0)
console.log(3)
setTimeout(function() {
console.log('定时器开始啦')
});
new Promise(function(resolve) {
console.log('马上执行for循环啦');
for(var i =0; i <10000; i++) {
i ==99 &&resolve();
}
}).then(function() {
console.log('执行then函数啦')
});
console.log('代码执行结束');
setTimeout(function(){
console.log('执行了')
},3000)
Node.js也是单线程的Event Loop,但是它的运行机制不同于浏览器环境。
process.nextTick(function A() {
console.log(1);
process.nextTick(function B(){console.log(2);});
});
setTimeout(function timeout() {
console.log('TIMEOUT FIRED');
}, 0)
setImmediate(function A() {
console.log(1);
setImmediate(function B(){
console.log(2);
});
});
setTimeout(function timeout() {
console.log('TIMEOUT FIRED');
}, 0);
setImmediate(function (){
setImmediate(function A() {
console.log(1);
setImmediate(function B(){console.log(2);});
});
setTimeout(function timeout() {
console.log('TIMEOUT FIRED');
}, 0);
});
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。