当前位置:网站首页>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
边栏推荐
- Google可能在春节后回归中国市场。
- Jerry needs to modify the profile definition of GATT [chapter]
- TS 体操 &(交叉运算) 和 接口的继承的区别
- 可变参数重载时的内存错误
- Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
- Emo diary 1
- Brief explanation of instagram operation tips in 2022
- 学go之路(一)go的基本介绍到第一个helloworld
- If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]
- Related operations of Excel
猜你喜欢
随机推荐
JMeter performance test steps practical tutorial
【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
可变参数重载时的内存错误
Jerry needs to modify the profile definition of GATT [chapter]
Brief explanation of instagram operation tips in 2022
Key value judgment in the cycle of TS type gymnastics, as keyword use
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
[JDBC] quick start tutorial
Typescript void base type
Le chemin du navigateur Edge obtient
QT color is converted to string and uint
杰理之如若需要大包发送,需要手机端修改 MTU【篇】
Jerry's ad series MIDI function description [chapter]
洛谷P1836 数页码 题解
Rust language - receive command line parameter instances
数字IC设计笔试题汇总(一)
Résumé de la structure du modèle synthétisable
word中把帶有某個符號的行全部選中,更改為標題
Structure summary of SystemVerilog integrable model