Introduction and usage of yield keyword in javascript
This article mainly explains the "introduction and use of the yield keyword in javascript". The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "the introduction and use of the yield keyword in javascript".
1. The yield keyword can only be used in the generator function, which means to pause the execution of the internal code of the function and return the current iteration data.
2. If there is no next yield,next, the done of the returned object will be placed as true.
After the yield keyword, the result of the expression returns the value as next.
Example
Def foo (): print ("starting...") While True: res = yield 4 print ("res:", res) g = foo () print (next (g)) print ("*" * 20) print (next (g)) Thank you for your reading. This is the content of "introduction and use of the yield keyword in javascript". After studying this article, I believe you have a deeper understanding of the introduction and use of the yield keyword in javascript. The specific use situation still needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!