当前位置:网站首页>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
边栏推荐
- Excel的相关操作
- NiO programming introduction
- Solution to the problem of breakthrough in OWASP juice shop shooting range
- Sélectionnez toutes les lignes avec un symbole dans Word et changez - les en titre
- word设置目录
- js对象获取属性的方法(.和[]方式)
- C intercept string
- Is the super browser a fingerprint browser? How to choose a good super browser?
- 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
- word中把帶有某個符號的行全部選中,更改為標題
猜你喜欢
Summary of Digital IC design written examination questions (I)
Related operations of Excel
成为优秀的TS体操高手 之 TS 类型体操前置知识储备
C - Inheritance - polymorphism - virtual function member (lower)
Compliance and efficiency, accelerate the digital transformation of pharmaceutical enterprises, and create a new document resource center for pharmaceutical enterprises
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
[cf gym101196-i] waif until dark network maximum flow
mysql如何合并数据
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
Leecode-c language implementation -15 Sum of three ----- ideas to be improved
随机推荐
C语言 简单易懂的高精度加法
How Navicat imports MySQL scripts
C - Inheritance - polymorphism - virtual function member (lower)
Chrome view page FPS
[window] when the Microsoft Store is deleted locally, how to reinstall it in three steps
TS 类型体操 之 extends,Equal,Alike 使用场景和实现对比
edge瀏覽器 路徑獲得
The way to learn go (I) the basic introduction of go to the first HelloWorld
Bit operation XOR
Redis builds clusters
edge浏览器 路径获得
Typescript indexable type
Wonderful use of TS type gymnastics string
OpenJudge NOI 2.1 1661:Bomb Game
QT color is converted to string and uint
Emo diary 1
Compliance and efficiency, accelerate the digital transformation of pharmaceutical enterprises, and create a new document resource center for pharmaceutical enterprises
Typescript interface and the use of generics
Structure summary of SystemVerilog integrable model
Relevant introduction of clip image