English 中文(简体)
采用[Symbol.iterator]可撤销的规程而不采用()
原标题:Javascript recursive generator/iterator class using [Symbol.iterator] iterable protocol without next()
  • 时间:2023-07-28 06:30:21
  •  标签:
  • javascript

复发发电机/自动取用器} IteratorClass{ 如下: 我发现了一个双向树木和复发的发电机/发电机例子,但没有文件或实例来支持我下面的做法,我很想知道,我是否需要做一些不同的事情。 我先测试了辛迪加和yn,看来是罚款。 然而,Im没有执行<代码>next(>)的功能,并且想知道Im是否做过错,因为大多数例子,I ve 看到采用了生成器Next(

Sync Plant/Iterator Level

class IteratorClass {
  constructor(obj) {
    this._obj = obj;
  }

  * [Symbol.iterator]() {
    for (const [key, value] of Object.entries(this._obj)) {
      /** remove code for brevity sake */

      /** type has childNode then yield to new instance of self */
      if (!value.hasChildNodes()) {
        yield* new IteratorClass(value)
      }

      yield type
    }
  }
}

<>Sync Iteration

const syncGenerator = new IteratorClass(obj)

for (const value of syncGenerator) {
    console.log( Yield value  :  , value)
}

http://www.ohchr.org。

class AsyncIteratorClass {
    /** remove code for brevity sake */

  async * [Symbol.asyncIterator]() {
    /** remove code for brevity sake, but identical implementation for this example */
    }
  }
}

<<>strong>Async Iteration

const asyncGenerator = new AsyncIteratorClass(obj)

async function init() {
  for await (const value of asyncGenerator) {
    console.log( Yield value  :  , value)
  }
}

init()
问题回答

您在通过该名录时使用<代码>next()。 反对<>for...of和Object.entries(......)。 如果您正在寻找文件,你可以看到:

<>Iteration protocol DN >>

<>代码>

接受零或一论点并退回符合<代码>的反对功能(见下文)。 如果在使用散装语文特征(例如<>条码/代码>)时,使用代号(例如<条码>的<>代码>),则将“)。

Generator | MDN

function* generator() {
  yield 1;
  yield 2;
  yield 3;
}

const gen = generator(); // "Generator { }"

console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // 3

Yield* | MDN

The yield* expression iterates over the operand and yields each value returned by it. It delegates iteration of the current generator to an underlying iterator — which we will refer to as "generator" and "iterator", respectively. yield* first gets the iterator from the operand by calling the latter s @@iterator method. Then, each time the <>代码> method of the generator is called, yield* calls the iterator s <>代码> method, passing the argument received by the generator s <>代码> method (always undefined for the first call), and yielding the same result object as what s returned from the iterator s <>代码> method. If the iterator result has done: true, then the yield* expression stops executing and returns the value of that result.

Yield | MDN

A yield expression. In this case, the generator pauses, and the <>代码> method return an iterator result object with two properties: value and done. The value property is the value of the expression after the yield operator, and done is false, indicating that the generator function has not fully completed.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签