当前位置:网站首页>Generator Foundation
Generator Foundation
2022-07-06 07:33:00 【Romantic bearded boy】
One 、 Basic grammar
//* It means that there will be yield
function* Function name () {
// Function content
yield;
}
Two 、 call Generator function
Generator Functions are the same as ordinary functions , It's all through Function name () To make the call :
Function name ();
however , Generator The function is called after , Does not execute internal code . But it will return an iterator object .
const it = Function name ();
next step , Calling iterator's next() Method to enter the function and execute the internal code of the function .
it.next();
3、 ... and 、yield
yield It can be used to block the execution of code in functions .
function* myGenerator() {
console.log('1、myGenerator Yes ');
yield;
console.log('2、myGenerator Yes ');
}
const it = myGenerator();
it.next();
it.next();
yield It can be followed by an expression :
function* myGenerator() {
console.log('1、myGenerator Yes ');
yield 'hello';
console.log('2、myGenerator Yes ');
yield 'world';
console.log('3、myGenerator Yes ');
}
const it = myGenerator();
console.log(it.next());
console.log(it.next());
next() You can also pass parameters , This parameter will be used as the current yield The return value of :
function* myGenerator() {
console.log('1、myGenerator Yes ');
const res = yield 'hello';
console.log('res', res);
}
const it = myGenerator();
console.log(it.next());
console.log(it.next("world"));
Four 、 Deal with asynchronous

边栏推荐
- TypeScript 接口属性
- ORACLE列转行--某字段按指定分隔符转多行
- Force buckle day31
- Summary of Digital IC design written examination questions (I)
- [CF Gym101196-I] Waif Until Dark 网络最大流
- [window] when the Microsoft Store is deleted locally, how to reinstall it in three steps
- C - Inheritance - hidden method
- Rust language - receive command line parameter instances
- word设置目录
- 杰理之BLE【篇】
猜你喜欢
![[computer skills]](/img/30/2a4506adf72eb4cb188dd64cce417d.jpg)
[computer skills]

Solution to the problem of breakthrough in OWASP juice shop shooting range

navicat如何导入MySQL脚本
![When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]](/img/3e/3d5bff87995b4a9fac093a6d9f9473.png)
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]

How Navicat imports MySQL scripts

QT color is converted to string and uint

C - Inheritance - polymorphism - virtual function member (lower)

Basics of reptile - Scratch reptile

Go learning --- use reflection to judge whether the value is valid

Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
随机推荐
Leecode-c language implementation -15 Sum of three ----- ideas to be improved
Relevant introduction of clip image
Word delete the contents in brackets
Twelve rules for naming variables
Select all the lines with a symbol in word and change them to titles
Typescript function definition
Basics of reptile - Scratch reptile
位运算异或
Word setting directory
Bugku CTF daily question: do you want seeds? Blackmailed
Summary of Digital IC design written examination questions (I)
[CF Gym101196-I] Waif Until Dark 网络最大流
C - Inheritance - hidden method
Jerry's ad series MIDI function description [chapter]
Google may return to the Chinese market after the Spring Festival.
Ble of Jerry [chapter]
TS类型体操 之 字符串的妙用
[window] when the Microsoft Store is deleted locally, how to reinstall it in three steps
Chrome view page FPS
Force buckle day31