JavaScript 执行机制

in js with 1 comment views: 1,705 times

例子

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('代码执行结束');

// 执行结果
马上执行for循环啦
代码执行结束
执行then函数啦
定时器开始啦

javascript事件循环

image

导图要表达的内容用文字来表述的话:

let data = [];
$.ajax({
    url:www.javascript.com,
    data:data,
    success:() => {
        console.log('发送成功!');
    }
})
console.log('代码执行结束');

上面是一段简易的ajax请求代码:


参考:
https://juejin.im/post/59e85eebf265da430d571f89


Responses
  1. Helpful advice. Regards.

    Reply