JavaScript是否在yield语句之后执行代码?
我在看一些Github代码,它看起来像是在yield语句后面有表达式 链接是,我看到的代码是:JavaScript是否在yield语句之后执行代码?,javascript,generator,Javascript,Generator,我在看一些Github代码,它看起来像是在yield语句后面有表达式 链接是,我看到的代码是: if (curbyte === LF && lastbyte !== CR || curbyte === CR && curpos < bytesRead - 1) { yield _concat(lineBuffer, readChunk.slice(startpos, curpos)); lineBuffer = undefined;
if (curbyte === LF && lastbyte !== CR || curbyte === CR && curpos < bytesRead - 1) {
yield _concat(lineBuffer, readChunk.slice(startpos, curpos));
lineBuffer = undefined;
startpos = curpos + 1;
if (curbyte === CR && readChunk[curpos + 1] === LF) {
startpos++;
curpos++;
}
} else if (curbyte === CR && curpos >= bytesRead - 1) {
lastbyte = curbyte;
}
在同一内,如果块永远无法到达。我这样说不对吗
JavaScript是否在yield语句之后执行代码
是的,但不是马上。当生成器生成时,它将暂停,直到迭代器对其调用next()
。然后生成器继续执行,直到再次生成
这里解释如下:
yield _concat(lineBuffer, readChunk.slice(startpos, curpos));