Skip to main content

Posts

Showing posts from July, 2022

ES6 generator functions

 Generators are a new function control and usage scheme in ES6 that gives you more control over how functions continue, pause, and more. We usually write a lot of functions, and the conditions for these functions to terminate are usually return values or exceptions. Generator functions are also functions, but with a few differences from regular functions. First, generator functions should add the symbol "*" after the function. The generator function can then use the yield keyword to control the execution. Finally, the return value of a generator function is a generator. A generator is actually a special kind of iterator.

A simple understanding of ES6 iterators

 What is an iterator?An iterator is an interface that provides a unified access mechanism for various data structures. Any data structure can complete the traversal operation as long as the iterator interface is deployed.ES6 created a new traversal command for...of loop, which natively has a data structure with the iterator interface (which can be traversed with for...of). Contains Array, Arguments, Set, Map, String, TypedArray, NodeList. Of course, you can also implement this interface manually, which is convenient for practical use.

Rest parameters and spread operator in ES6

 This article mainly introduces the usage of ES6 spread operator and rest operator, and analyzes the basic functions, usage and operation precautions of ES6 spread operator and rest operator in combination with examples.

ES6 arrow functions

 In ES6, in addition to the new features of let and const, arrow functions are the most frequently used new features. But this feature is not unique to ES6. Arrow functions, as the name suggests, are functions defined using arrows (=>) and belong to a class of anonymous functions. It allows us to write smaller function syntaxes. The code of arrow functions is simpler and more flexible to write.