In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what is the role of es6 eraser". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In es6, the Iterator is a kind of interface, which is used to deal with different data structures and provides a unified access mechanism for different data structures. As long as the Iterator interface is deployed in the data structure, the traversal operation can be completed; the traversal can make the members of the data structure arrange in a certain order.
This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.
What is the es6 traversal?
JavaScript's original data structures for "collections" are mainly arrays (Array) and objects (Object), and ES6 adds Map and Set. In this way, there are four kinds of data collections, and users can combine them to define their own data structures, for example, the members of the array are Map,Map members are objects. This requires a unified interface mechanism to handle all different data structures.
The Iterator is such a mechanism. It is an interface that provides a unified access mechanism for different data structures. Any data structure can be traversed as long as the Iterator interface is deployed (that is, all members of the data structure are processed in turn).
The traversal Iterator is an interface that provides a unified access mechanism for a variety of different data structures, namely for...of loops.
Any data structure can be traversed as long as the Iterator interface is deployed.
The function of the ergodic
Provide a unified and simple access interface for various data structures.
Enables the members of the data structure to be arranged in a certain order
ES6 created a new traversal command, for. Of loop, Iterator interface is mainly for for. Of consumption (objects traversed by for of must have an ergodic interface to traverse)
The traversal process of Iterator
Creates a pointer object that points to the starting position of the current data structure. In other words, the traversal object is essentially a pointer object.
The first time you call the next method of the pointer object, you can point the pointer to the first member of the data structure.
The second time you call the next method of the pointer object, the pointer points to the second member of the data structure.
The next method of the pointer object is called until it points to the end of the data structure.
Each time the next method is called, information about the current member of the data structure is returned. Specifically, it returns an object that contains value and done properties. Where the value property is the value of the current member and the done property is a Boolean value indicating whether the traversal ends.
Examples are as follows:
Common implementation
Function makeInterator (array) {let startIndex=0; return {next:function () {return startIndex
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.