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

说一下 generator #55

Open
nmsn opened this issue May 17, 2023 · 1 comment
Open

说一下 generator #55

nmsn opened this issue May 17, 2023 · 1 comment
Labels

Comments

@nmsn
Copy link
Contributor

nmsn commented May 17, 2023

如题

@nmsn nmsn added the ES6 label May 17, 2023
@nmsn
Copy link
Contributor Author

nmsn commented May 17, 2023

Generator 是一种特殊的函数,可以在运行过程中暂停并恢复。在每次运行到 yield 关键字时,函数会暂停,并将 yield 后面的表达式的值作为函数的返回值。之后,每次再调用 next() 方法时,函数会从上次暂停的位置继续执行,直到再次遇到 yield 关键字。

通过使用 Generator,我们可以更灵活地控制异步操作的执行,例如实现以同步的方式书写异步代码。此外,Generator 还可以用于实现惰性计算、迭代器、状态机等复杂的流程控制场景。

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

No branches or pull requests

1 participant