In es6, the generator is a function that sets the iterator. Calling the generator function can return an iterable object; there is an "*" sign between the function and the function name in the generator, and the function The yield expression is used inside the body, and the syntax is "function*gen(){yield1;yield2;}".
The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.
What does the es6 generator mean?
The generator is a function used to set iterators in Es6. We can understand it this way: the generator ultimately generates an iterator.
Generator is a new data type introduced by the ES6 standard.
A generator looks like a function, but can return multiple times.
There are two differences between the generator function and the ordinary function,
1: There is an * between the function and the function name,
2: The yield expression is used inside the function body
Calling a generator function is different from calling a normal function. Calling a generator function returns a generator object (iterable Object)
Generator: There is an iterator interface in the generator, which means that the generator itself can be iterated, that is, creating a generator is equivalent to creating an iterator. Regarding the use of generators, for some data types that do not have an iterator interface, we can use a generator to customize an iterator for iteration.
The above is my understanding of the generator itself. The specific syntax is explained below.
Some properties of the generator
//生成器的声明 <script> function* generator(){ } let test = generator(); console.log(test); </script>
//生成器中的yield关键字 <script> function* Generator(){ yield 100; yield 200; yield 300; yield 400; } let test = Generator(); console.log(test.next()); console.log(test.next()); console.log(test.next()); console.log(test.next()); console.log(test.next()); console.log(test.next()); console.log(test.next()); </script>
Final result:
Parsing: Due to the generator instantiating the object There is next() in the prototype. When next() is executed, it will be iterated according to yield.
【Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of What does es6 generator mean?. For more information, please follow other related articles on the PHP Chinese website!

Classesarebetterforaccessibilityinwebdevelopment.1)Classescanbeappliedtomultipleelements,ensuringconsistentstylesandbehaviors,whichaidsuserswithdisabilities.2)TheyfacilitatetheuseofARIAattributesacrossgroupsofelements,enhancinguserexperience.3)Classe

Classselectorsarereusableformultipleelements,whileIDselectorsareuniqueandusedonceperpage.1)Classes,denotedbyaperiod(.),areidealforstylingmultipleelementslikebuttons.2)IDs,denotedbyahash(#),areperfectforuniqueelementslikeanavigationmenu.3)IDshavehighe

In CSS style, the class selector or ID selector should be selected according to the project requirements: 1) The class selector is suitable for reuse and is suitable for the same style of multiple elements; 2) The ID selector is suitable for unique elements and has higher priority, but should be used with caution to avoid maintenance difficulties.

HTML5hasseverallimitationsincludinglackofsupportforadvancedgraphics,basicformvalidation,cross-browsercompatibilityissues,performanceimpacts,andsecurityconcerns.1)Forcomplexgraphics,HTML5'scanvasisinsufficient,requiringlibrarieslikeWebGLorThree.js.2)I

Yes,onestylecanhavemoreprioritythananotherinCSSduetospecificityandthecascade.1)Specificityactsasascoringsystemwheremorespecificselectorshavehigherpriority.2)Thecascadedeterminesstyleapplicationorder,withlaterrulesoverridingearlieronesofequalspecifici

ThesignificantgoalsofHTML5aretoenhancemultimediasupport,ensurehumanreadability,maintainconsistencyacrossdevices,andensurebackwardcompatibility.1)HTML5improvesmultimediawithnativeelementslikeand.2)ItusessemanticelementsforbetterreadabilityandSEO.3)Its

React'slimitationsinclude:1)asteeplearningcurveduetoitsvastecosystem,2)SEOchallengeswithclient-siderendering,3)potentialperformanceissuesinlargeapplications,4)complexstatemanagementasappsgrow,and5)theneedtokeepupwithitsrapidevolution.Thesefactorsshou

Reactischallengingforbeginnersduetoitssteeplearningcurveandparadigmshifttocomponent-basedarchitecture.1)Startwithofficialdocumentationforasolidfoundation.2)UnderstandJSXandhowtoembedJavaScriptwithinit.3)Learntousefunctionalcomponentswithhooksforstate


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
