javascript asynchronous programming_javascript skills
May 16, 2016 pm 06:25 PM就好像排队,前面的人忙着忙着突然上厕所了,后面的人阻塞在这里,因此我们就需要让前面的人死到一边去,让后面的人跟进……AJAX就是这个概念,请求还在继续,但我们还可以做其他事。
javascript中实现这个功能的是来自BOM的一个函数setTimeout,但相关的DOM操作也提供了一系列实现。如XMLHttpRequest对象与script标签的onreadystatechange回调,image的onload与onerror回调,iframe的onload,DOM元素的事件回调,HTML5的跨域消息传送postMessage,QuickTime与flash对象的加载……
setTimeout的零秒延迟在前些年时间被国内宣扬得特别厉害,但setTimeout是所有延迟中最慢的,最少要花上10多毫秒,如果用setTimeout来开发特效,这特效会运行得比较慢。下面是一个性能测试:

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement asynchronous programming with C++ functions?

Asynchronous Programming of JavaScript Functions: Essential Tips for Handling Complex Tasks

How to use ReactPHP for asynchronous programming in PHP

How to implement asynchronous message handling in PHP

In-depth understanding of the new features of PHP8: How to use asynchronous programming and code efficiently?

How does the golang framework handle concurrency and asynchronous programming?

Common problems and solutions in asynchronous programming in Java framework

What are the advantages and disadvantages of asynchronous programming in PHP?
