作家
登录

JavaScript Event Loop机制详解与Vue.js中nextTick的实践应用

作者: 来源: 2017-09-12 10:24:34 阅读 我要评论

contains only platform code. [3.1].     
  •  
  • Here “platform code” means engine, environment, and promise implementation code. In practice, this requirement ensures that onFulfilled and onRejected execute asynchronously, after the event loop turn in which then is called, and with a fresh stack. This can be implemented with either a “macro-task” mechanism such as setTimeout or setImmediate, or with a “micro-task” mechanism such as MutationObserver or process.nextTick. Since the promise implementation is considered platform code, it may itself contain a task-scheduling queue or “trampoline” in which the handlers are called. 
  • 规范请求,onFulfilled 必须在履行高低文┞坊(Execution Context Stack) 只包含 平台代码(platform code) 后才能履行。平台代码指引擎,情况,Promise 实现代码等。实践上来说,这个请求包管了>

  • // 测试代码 
  •  
  • console.log('main1'); 
  •  
  •   
  •  
  • // 该函数仅在 Node.js 情况下可以应用 
  •  
  • process.nextTick(function() { 
  •  
  •     console.log('process.nextTick1'); 
  •  
  • }); 
  •  
  •   
  •  
  • setTimeout(function() { 
  •  
  •     console.log('setTimeout'); 
  •  
  •     process.nextTick(function() { 
  •  
  •         console.log('process.nextTick2'); 
  •  
  •     }); 
  •  
  • }, 0); 
  •  
  •   
  •  
  • new Promise(function(resolve, reject) { 
  •  
  •     console.log('promise'); 
  •  
  •     resolve(); 
  •  
  • }).then(function() { 
  •  
  •     console.log('promise then'); 
  •  
  • }); 
  •  

      推荐阅读

      借力大数据技术 证券行业迎转型契机

    51CTO诚邀您9月23号和秒拍/国美/美团元专家一路聊智能CDN的优化之路,抓紧时光哦! 互联网+时代,证券行业制订大年夜数据计谋急切而合时。一方面,近年来大年夜数据被晋升到国度成长计谋层>>>详细阅读


    本文标题:JavaScript Event Loop机制详解与Vue.js中nextTick的实践应用

    地址:http://www.17bianji.com/lsqh/37333.html

  • 关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)