Asynchronous JavaScript - Learn web development 编辑
Looking to become a front-end web developer?
In this module we take a look at asynchronous JavaScript, why it is important, and how it can be used to effectively handle potential blocking operations such as fetching resources from a server.
We have put together a course that includes all the essential information you need to work towards your goal.
Prerequisites
Asynchronous JavaScript is a fairly advanced topic, and you are advised to work through JavaScript first steps and JavaScript building blocks modules before attempting this.
If you are not familiar with the concept of asynchronous programming, you should definitely start with the General asynchronous programming concepts article in this module. If you are, then you can probably skip to the Introducing asynchronous JavaScript module.
Note: If you are working on a computer/tablet/other device where you don't have the ability to create your own files, you can try out (most of) the code examples in an online coding program such as JSBin or Glitch.
Guides
- General asynchronous programming concepts
In this article we'll run through a number of important concepts relating to asynchronous programming, and how this looks in web browsers and JavaScript. You should understand these concepts before working through the other articles in the module.
- Introducing asynchronous JavaScript
- In this article we briefly recap the problems associated with sychronous JavaScript, and take a first look at some of the different asynchronous JavaScript techniques you'll encounter, showing how they can help us solve such problems.
- Cooperative asynchronous JavaScript: Timeouts and intervals
- Here we look at the traditional methods JavaScript has available for running code asychronously after a set time period has elapsed, or at a regular interval (e.g. a set number of times per second), talk about what they are useful for, and look at their inherent issues.
- Handling async operations gracefully with Promises
- Promises are a comparatively new feature of the JavaScript language that allow you to defer further actions until after the previous action has completed, or respond to its failure. This is really useful for setting up a sequence of operations to work correctly. This article shows you how promises work, where you'll see them in use in WebAPIs, and how to write your own.
- Making asynchronous programming easier with async and await
- Promises can be somewhat complex to set up and understand, and so modern browsers have implemented
async
functions and theawait
operator. The former allows standard functions to implicitly behave asynchronously with promises, whereas the latter can be used insideasync
functions to wait for promises before the function continues. This makes chaining promises simpler and easier to read. - Choosing the right approach
- To finish this module off, we'll consider the different coding techniques and features we've discussed throughout, looking at which ones you should use when, with recommendations and reminders of common pitfalls where appropriate.
See also
- Asynchronous Programming from the fantastic Eloquent JavaScript online book by Marijn Haverbeke.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论