当前位置:网站首页>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

边栏推荐
- word中如何删除某符号前面或后面所有的文字
- Apache middleware vulnerability recurrence
- OpenJudge NOI 2.1 1661:Bomb Game
- TypeScript void 基础类型
- C # create database connection object SQLite database
- Key value judgment in the cycle of TS type gymnastics, as keyword use
- Mise en œuvre du langage leecode - C - 15. Somme des trois chiffres - - - - - idées à améliorer
- 杰理之AD 系列 MIDI 功能说明【篇】
- If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
- 可变参数重载时的内存错误
猜你喜欢

【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程

jmeter性能测试步骤实战教程

word中如何删除某符号前面或后面所有的文字

Markdown 中设置图片图注
![[CF Gym101196-I] Waif Until Dark 网络最大流](/img/66/6b339fc23146b5fbdcd2a1fa0a2349.png)
[CF Gym101196-I] Waif Until Dark 网络最大流

【mysql学习笔记30】锁(非教程)
![If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]](/img/57/12a97ab3d2dabfaf06bbe1788450cf.png)
If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Summary of Digital IC design written examination questions (I)
![Ble of Jerry [chapter]](/img/00/27486ad68bf491997d10e387c32dd4.png)
Ble of Jerry [chapter]
随机推荐
【mysql学习笔记30】锁(非教程)
C语言 简单易懂的高精度加法
After the hot update of uniapp, "mismatched versions may cause application exceptions" causes and Solutions
How can word delete English only and keep Chinese or delete Chinese and keep English
杰理之普通透传测试---做数传搭配 APP 通信【篇】
[computer skills]
js对象获取属性的方法(.和[]方式)
Multithreading and concurrent programming (2)
Scala language learning-08-abstract classes
Google可能在春节后回归中国市场。
Set picture annotation in markdown
word中把帶有某個符號的行全部選中,更改為標題
Fundamentals of C language 9: Functions
合规、高效,加快药企数字化转型,全新打造药企文档资源中心
Force buckle day31
杰理之BLE【篇】
Bloom taxonomy
Scala语言学习-08-抽象类
How MySQL merges data
洛谷P4127 [AHOI2009]同类分布 题解