xxx国产老太婆视频,91免费观看网站,久久狠狠高潮亚洲精品,国产综合免费视频,手机福利在线视频,**性23式(动)黄色毛片

Professional JavaScript for Web Developers 第四版學習筆記 CHAPTER 7: ITERATORS AND GENERATORS

歡歡歡歡 發(fā)表于 2021-4-5 08:42

Introduction to Iteration 225
The Iterator Pattern 226
The Iterable Protocol 227
The Iterator Protocol 229
Custom Iterator Definition 231
Early Termination of Iterators 233
Generators 236
Generator Basics 236
Interrupting Execution with “yield” 238
  Using a Generator Object as an Iterable 239
  Using “yield” for Input and Output 240
  Yielding an Iterable 242
  Recursive Algorithms Using yield* 244
Using a Generator as the Default Iterator 246
Early Termination of Generators 247
  The return() Method 247
  The throw() Method 248
Summary 249

-------------------------------------------------

next()

let arr = ['foo'];
let iter = arr[Symbol.iterator]();
console.log(iter.next()); // { done: false, value: 'foo' }
console.log(iter.next()); // { done: true, value: undefined }

-------------------------------------------------

yield*

It is possible to augment the behavior of yield to cause it to iterate through an iterable and yield its contents one at a time. This can be done using an asterisk, as shown here:

// generatorFn is equivalent to:
// function* generatorFn() {
//  for (const x of [1, 2, 3]) {
//   yield x;
//  }
// }
function* generatorFn() {
 yield* [1, 2, 3];
}