1

Javascript ジェネレーターの現在の仕様を理解しているので、yields を含む関数を明示的にマークする必要があります。

この背後にある合理性は何なのだろうか。

これが本当なら、人々は次のように書くことを強いられるでしょう:

let thirdfunc = function*() {
  let value = 5;
  let other = yield 6;
  return value;
};

let secondfunc = function*() {
  yield thirdfunc();
};

let firstfunc = function*() {
  yield secondfunc();
};

let gen = function*() {
  // some code
  // more code
  yield firstfunc();
  // and code
};

let it = gen();
while( !it.done() ) {
  it.next();
};

つまり、ジェネレーターはコードベースでガンのように拡散します。結局のところ、イテレータを生成して処理するだけの開発者にとっては、非常に興味深いことです。

繰り返しを処理したい場所を定義するだけで、はるかに実用的だと思います。

let thirdfunc = function() {
  let value = 5;
  let other = yield 6; // Change 1: incorporate yield
  return value;
};

let secondfunc = function() {
  thirdfunc();
};

let firstfunc = function() {
  secondfunc();
};

let gen = function*() { // Change 2: at this level I want to deal with descendant yields
  // some code
  // more code
  firstfunc();
  // and code
};

// Change 3: Handle iterator
let it = gen();
while( !it.done() ) {
  it.next();
}

ブラウザがyield呼び出しとジェネレータ ハンドラ ( firstfuncsecondfuncthirdfunc) の間のすべてをpromise / futureフォームに変換する必要がある場合、それは自動的に機能し、Javascript 開発者の仕事ではありません。

または、これを行わないことについて本当に良い議論がありますか?

4

1 に答える 1