In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what yield means in es6, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
In es6, yield is the keyword that the generator uses to pause itself internally; yield is followed by a generator function or other iterable object, and the return value of the yield expression is the return value of the iterable object after it is iterated. The syntax is "function*gen () {yield expression}".
This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.
What does yield mean in es6
Yield is the keyword that the Generator (generator) in ES6 uses to pause itself internally.
Note the word "inside" that the generator function cannot be paused by external logic, but only by itself via yield.
The yield keyword can be followed by a variable or can be used alone. If yield is followed by a variable (we can call it an yield expression), when the generator function resumes running again after a pause, the passed parameter participates in the subsequent logical operation as the value of the overall yield expression
When yield is not followed by a variable, the yield used alone is only used as a pause generator function, and the parameters passed in after the generator resumes operation participate in the subsequent operation as the value of yield.
Give an example
Step 1, construct a generator function.
Function* numbers () {yield 1; yield 2; return 'numbers';}
Step 2, do a proxy on the outer layer of the generator function above.
Function* delegate () {var str = yield* numbers (); console.log (str); yield 3; return 'delegate';}
Step 3, construct an iterator.
Var iterator = delegate ()
Step 4, output the iteration results.
/ * first output * {value: 1, done: false} * / console.log (iterator.next ()) / / first output / * second output * {value: 2, done: false} * / console.log (iterator.next ()) / / second output / * third output * numbers * {value: 3 Done: false} * / console.log (iterator.next ()) / / third output / * fourth output result * {value: 'delegate', done: true} * / console.log (iterator.next ()) / / fourth output
Output result description
On the third output, two lines are output. The first line is the output of console.log (str) in the delegate function, and the value is the return value of the numbers function.
On the fourth output, a line is output, where the value value is the return value of the delegate function. At this point, the done property is true.
The above is all the content of this article "what does yield in es6 mean?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.