5

javascript 异步操作的6种方法

 2 years ago
source link: https://blog.p2hp.com/archives/9417
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

javascript 异步操作的6种方法

异步操作的模式:

1 回调函数
2 事件监听
3 发布/订阅

4 Promise 是异步编程的一种解决方案,比传统的解决方案——回调函数和事件——更合理和更强大。它由社区最早提出和实现,ES6 将其写进了语言标准,统一了用法,原生提供了Promise对象

5 Generator 函数是 ES6 提供的一种异步编程解决方案,语法行为与传统函数完全不同,Generator 函数将 JavaScript 异步编程带入了一个全新的阶段。

6 async 函数:ES2017 标准引入了 async 函数,使得异步操作变得更加方便。

async 函数是什么?一句话,它就是 Generator 函数的语法糖。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK