Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

异步方案 #13

Open
Lawguancong opened this issue Aug 23, 2021 · 0 comments
Open

异步方案 #13

Lawguancong opened this issue Aug 23, 2021 · 0 comments

Comments

@Lawguancong
Copy link
Owner

Lawguancong commented Aug 23, 2021

回调函数

• 优点:简单、容易理解
• 缺点:不利于维护,代码耦合高

事件监听(采用时间驱动模式,取决于某个事件是否发生)

• 优点:容易理解,可以绑定多个事件,每个事件可以指定多个回调函数
• 缺点:事件驱动型,流程不够清晰

发布/订阅(观察者模式)

• 类似于事件监听,但是可以通过‘消息中心‘,了解现在有多少发布者,多少订阅者

Promise对象

• 优点:可以利用then方法,进行链式写法;可以书写错误时的回调函数;
• 缺点:编写和理解,相对比较难

Generator函数

• 优点:函数体内外的数据交换、错误处理机制
• 缺点:流程管理不方便

async await函数

• 优点:内置执行器、更好的语义、更广的适用性、返回的是Promise、结构清晰。
• 缺点:错误处理机制

参考链接
http://www.ruanyifeng.com/blog/2012/12/asynchronous%EF%BC%BFjavascript.html
Advanced-Frontend/Daily-Interview-Question#11
https://www.infoq.cn/article/zwowtega7KjC4Ad-trp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant