4. 浅析 Vue.js 中 nextTick 的实现
其对应的函数调用图(整顿自这里)为:

这里还值得一提的是,Promise.then 是异步履行的,而创建 Promise 实例 (executor) 是同步履行的,譬如下述代码:
- (function test() {
- setTimeout(function() {console.log(4)}, 0);
- new Promise(function executor(resolve) {
- console.log(1);
- for( var i=0 ; i<10000 ; i++ ) {
- i == 9999 && resolve();
- }
- console.log(2);
- }).then(function() {
- console.log(5);
- });
- console.log(3);
- })()
- // 输出结不雅为:
- // 1
- // 2
- // 3
- // 5
- // 4
我们可以参考 Promise 规范中有关于 promise.then 的部分:
- promise.then(onFulfilled, onRejected)
- 2.2.4 onFulfilled or onRejected must not be called until the execution context stack
推荐阅读
51CTO诚邀您9月23号和秒拍/国美/美团元专家一路聊智能CDN的优化之路,抓紧时光哦! 互联网+时代,证券行业制订大年夜数据计谋急切而合时。一方面,近年来大年夜数据被晋升到国度成长计谋层>>>详细阅读
本文标题:JavaScript Event Loop机制详解与Vue.js中nextTick的实践应用
地址:http://www.17bianji.com/lsqh/37333.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示