惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
MongoDB | Blog
MongoDB | Blog
V
V2EX
博客园 - 【当耐特】
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
Martin Fowler
Martin Fowler
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
B
Blog
V
Visual Studio Blog
D
DataBreaches.Net
C
Check Point Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Fortinet All Blogs

博客园 - 果然如此

微信小程序UI组件、开发框架、实用库 sql查询优化--数字转换字符串字段 Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad Git简易的命令行入门教程 .NET Framework 历史版本(2017年) spring boot maven多模块打包部署到tomcat TypeScript白鹭引擎Egret防止按钮事件冒泡穿透 maven多模块启动required a bean of type com.xxx.xxx.service that could not be found. idea常用快捷键 启动类加注解@MapperScan spring boot mybatis 启动错误 Maven项目mybatis Invalid bound statement (not found)解决方法 Re:从零开始的Spring Security Oauth2(三) Re:从零开始的Spring Security Oauth2(二) Re:从零开始的Spring Security Oauth2(一) typescript多维对象数组仿List泛型 TypeScript 基本语法 idea新建maven项目没有src目录 spring boot 错误:Check your ViewResolver setup 《乔布斯传》经典摘录(七)
深入理解 JavaScript 事件循环(一)— event loop
果然如此 · 2018-04-16 · via 博客园 - 果然如此

javascript事件循环和异步测试:

console.log("script start");    
    setTimeout(function () {
             console.log("setTimeout");
         }, 0);   
     //具体数字不定,这取决于你的硬件配置和浏览器
     for(var i = 0; i < 1000000; i ++){
         //do something        
     }   
     console.log("script end");
  var arr = new Array(10000);
    arr.fill(1);
    function asyncForEach(array, handler){
        var t = setInterval(function () {
            if(array.length === 0){
                clearInterval(t);
            }else {
                handler(arr.shift());
            }
        }, 0);
    }

    //异步遍历
    asyncForEach(arr, function (value) {
        console.log(value);
    });

    //同步遍历
    arr.forEach(function (value, index, arr) {
        console.log(value);
    });

来源:https://www.cnblogs.com/dong-xu/p/7000163.html