我在Mozilla Dev頁面查看生成器函數。關於生成器函數send()javascript
有一個示例代碼,它具有send()函數。
function* fibonacci() {
var a = yield 1;
yield a * 2;
}
var it = fibonacci();
console.log(it); // "Generator { }"
console.log(it.next()); // 1
console.log(it.send(10)); // 20
console.log(it.close()); // undefined
console.log(it.next()); // throws StopIteration (as the generator is now closed)
但是,Chrome和Firefox(最新版本)都在send()函數上拋出錯誤。
對此有何看法?它不支持?
我記得,只有有限的瀏覽器支持ES6,你最好使用像transpilers BabelJS –
在ES6,有隻有你傳遞值的'next'方法。你在看什麼頁面?請鏈接它,以便我們解決它(不要忘記MDN是一個wiki!) – Bergi