当前位置: 首页 > news >正文

广告推广精准引流南昌网站建设优化

广告推广精准引流,南昌网站建设优化,花都有沒有网站建设的,制作网页表白借鉴: 《Javascript 忍者秘籍》第二版,事件循环篇 面试 | JS 事件循环 event loop 经典面试题含答案 - 知乎 (zhihu.com) 概念 主栈队列就是一个宏任务,每一个宏任务执行完就会执行宏任务中的微任务,直到微任务全部都执行完&a…
借鉴:

《Javascript 忍者秘籍》第二版,事件循环篇

面试 | JS 事件循环 event loop 经典面试题含答案 - 知乎 (zhihu.com)

概念

  1. 主栈队列就是一个宏任务,每一个宏任务执行完就会执行宏任务中的微任务,直到微任务全部都执行完,才开始执行下一个宏任务。
  2. JS 中任务的执行顺序优先级是:主栈全局任务(宏任务) > 宏任务中的微任务 > 下一个宏任务。,所以 promise(微任务).then() 的执行顺序优先级高于setTimeout定时器。
  3. 不能满目的将 .then 的回调放入微任务队列;因为没有调用 resolve或者reject 之前是不算异步任务完成的, 所以不能将回调随意的放入微任务事件队列
  4. await 是一个让出线程的标志。await 后面的表达式会先执行一遍,将 await 后面的代码加入到 micro task中这个微任务是 promise 队列中微任务,然后就会跳出整个 async 函数来继续执行后面的代码。
  5. process.nextTick 是一个独立于 eventLoop 的任务队列,主栈中的宏任务每一次结束后都是先执行 process.nextTick队列,在执行微任务 promise 的 .then()
  6. 每一个宏任务和宏任务的微任务执行完后都会对页面 UI 进行渲染
  • 宏任务 macrotask
    • script 整体代码
    • setTimeout
    • setInterval
    • setImmediate
    • I/O
    • ui render
  • 微任务 microtask
    • process.nextTick
    • promise.then
    • await 后面的代码
    • MutationObserver(h5新特性)

为什么 await 后面的代码会进入到promise队列中的微任务?

async/await 只是操作 promise 的语法糖,最后的本质还是promise
async function async1() {console.log('async1 start');await async2();console.log('async1 end');
}
// 上面的代码等价于 ==>
async function async1() {console.log('async1 start');Promise.resolve(async2()).then(() => {console.log('async1 end')})
}

面试题

面试题1

async function async1() {console.log('1') // 2async2().then(() => {console.log('2')})
}
async function async2() {console.log('3') // 3
}
console.log('4') // 1
setTimeout(function () {console.log('5')
}, 0)
async1();
new Promise(function (resolve) {console.log('6') // 4resolve();
}).then(function () {console.log('7')
})
console.log('8') // 5
//4 1 3 6 8 2 7 5

面试题2


setTimeout(() => {console.log(1);}, 0);async function main1() {new Promise((resolve, reject) => {console.log(2);resolve();}).then(() => {console.log(3);})await main2();console.log(7);}function main2() {console.log(8);}main1();setTimeout(() => {console.log(10);}, 0);//  
2
8
3
7
1
10

面试题3

Promise.resolve().then(() => {console.log(0);return Promise.resolve('4x');}).then((res) => { console.log(res) })
Promise.resolve().then(() => { console.log(1); }).then(() => { console.log(2); }, () => { console.log(2.1) }).then(() => { console.log(3); }).then(() => { console.log(5); }).then(() => { console.log(6); })// 0 1 2 3 4x 5 6

面试题4  详解:(1 封私信) 关于promise输出顺序的疑问? - 知乎 (zhihu.com)

new Promise((resolve,reject) => {console.log('外部promise')resolve()
})
.then(() => {console.log('外部第一个then')new Promise((resolve,reject) => {console.log('内部promise')resolve()}).then(() => {console.log('内部第一个then')return Promise.resolve()}).then(() => {console.log('内部第二个then')})
})
.then(() => {console.log('外部第二个then')
})
.then(() => {console.log('外部第三个then')
})
.then(() => {console.log('外部第四个then')
})	// 
外部promise外部第一个then内部promise
内部第一个then
外部第二个then
外部第三个then外部第四个then内部第二个then

面试题5

// A 任务
setTimeout(() => {console.log(1)
}, 20)// B 任务
setTimeout(() => {console.log(2)
}, 0)// C 任务
setTimeout(() => {console.log(3)
}, 10)// D
setTimeout(() => {console.log(5)
}, 10)console.log(4)
/* 输出
*   4 -> 2-> 3 -> 5 -> 1
*/

面试题6

setTimeout(function () {console.log(1)
}, 0);new Promise(function (resolve, reject) {console.log(2)for (var i = 0; i < 10000; i++) {if (i === 10) {console.log(10)}i == 9999 && resolve();}console.log(3)
}).then(function () {console.log(4)
})
console.log(5);
// 2, 10, 3, 5, 4, 1

面试题7

console.log("start");
setTimeout(() => {console.log("children2")Promise.resolve().then(() =>{console.log("children3")})
}, 0)new Promise(function(resolve, reject){console.log("children4")setTimeout(function(){console.log("children5")resolve("children6")}, 0)
}).then(res =>{         // flagconsole.log("children7")setTimeout(() =>{console.log(res)}, 0)
})
// start children4 children2 children3  children5  children7 children6

面试题8

这道题的难点在于是 promise2还是 async1 end 先输出。从全局宏任务之上而下执行时 await async2() 后面的代码 console.log('async1 end') 先进入 promise 中的微任务队列,最后.then() 中的console.log('promise2') 再进入到 promise 中的微任务队列。所以再开始下一轮宏任务循环之前先输出了 async1 end 再输出了 promise2。全局中的微任务执行完成开始下一轮宏任务setTimeout 最后输出 setTimeout

async function async1() {console.log('async1 start')await async2()console.log('async1 end')
}
async function async2() {console.log('async2')
}
console.log('script start')
setTimeout(function () {console.log('setTimeout')
}, 0)
async1()
new Promise((resolve) => {console.log('promise1')resolve()
}).then(function () {console.log('promise2')
})
console.log('script end')
//输出
//script start
//async1 start
//async2
//promise1
//script end
//async1 end
//promise2
//setTimeout

面试题9 

首先开始全局下的宏任务依次输出 script start, async1 start, promise1, promise3, script end。其中 await async2();async2() 中.then()的代码先进入到promise的微任务队列,await async2(); 后面的代码再进入到promise的任务队列,console.log('promise4'); 最后进入到 promise 的任务队列。全局下的宏任务结束,开始全局下的微任务,promise 的微任务队列中按照队列的先进先出原则依次输出,promise2,async1 end,promise4。全局微任务结束,开始下一轮的宏任务setTimeout,最终输出 setTimeout

async function async1() {console.log('async1 start');await async2();console.log('async1 end');
}
async function async2() {new Promise(function (resolve) {console.log('promise1');resolve();}).then(function () {console.log('promise2');});
}
console.log('script start');
setTimeout(function () {console.log('setTimeout');
}, 0)
async1();
new Promise(function (resolve) {console.log('promise3');resolve();
}).then(function () {console.log('promise4');
});
console.log('script end');
//script start, 
// async1 start, 
// promise1, 
// promise3, 
// script end, 
// promise2,
// async1 end,
// promise4, 
// setTimeout

面试题10

async function async1() {console.log('async1 start');await async2();setTimeout(function() {console.log('setTimeout1')  // 这一部分代码会放入到 promise 的微任务队列中。},0)
}
async function async2() {setTimeout(function() {console.log('setTimeout2')},0)
}
console.log('script start');
setTimeout(function() {console.log('setTimeout3');
}, 0)
async1();
new Promise(function(resolve) {console.log('promise1');resolve();
}).then(function() {console.log('promise2');
});
console.log('script end');
// script start, async1 start, promise1, script end,
// promise2, setTimeout3,  setTimeout2, setTimeout1

http://www.yayakq.cn/news/836190/

相关文章:

  • 自己做的网站怎么给域名备案wordpress网站可以显示中文和英文
  • 公司搭建一个网站需要多少钱网站建设工作室门头
  • 现在做网站怎么样电子商务与网站建设论文
  • 做烘焙网站国外黄冈网站推广软件免费吗
  • 5g创业网站建设中企动力企业邮箱电脑版
  • 网站建设详细流程上海交通大学毕业设计网站
  • 手机网站特效做微信的微网站
  • 泰安网站建设方案书东莞厚街职业技术学校
  • 还有哪些网站可以做淘宝活动垂直网站怎么做
  • 重庆网站制作有名 乐云践新ui设计周末培训机构
  • 最新款淘宝客源码整网站程序模板+后台带自动采集商品功能带文章河南天元建设公司网站
  • 邢台外贸网站建设安源网站建设
  • 专业企业建站价格无刷新网站
  • 网站服务器是什么意思网站建设-猴王网络
  • 杭州做网站怎么收费个人邮箱登录注册
  • 西昌规划和建设局网站东莞市企业网站建设哪家好
  • 手机网站大全123456中午网站做google广告好吗
  • 网站ico图标 代码成都动力无限科技有限公司做网站
  • 宁波公司核名网站WordPress主题Adams
  • 信阳网站开发wordpress兑换卡密
  • 南县做网站莞城区做网站
  • 自己做的网站如何上首页做明星个人资料网站
  • 专业做网站的公司 郑州景县网址建站
  • 海报素材网站推荐秦皇岛庆云网站建设
  • 自己做文学网站赚钱吗即墨网站建设即墨
  • 做网站时怎么裁切存图济南网络建站
  • 如何建开发手机网站首页怎么创办个人网站
  • 红色网站建设大连建设学校网站
  • 网站广告设计成都优化网站关键词
  • 成品网站源码免费分享经典创意设计300例