【发布时间】:2019-03-20 17:49:35
【问题描述】:
以下 js 代码在 firefox、chrome 和 nodejs 的开发者控制台中也失败。不知道为什么?
function* x() {}
let y = x()
setTimeout(y.next, 100)
火狐浏览器出错
TypeError: CallGeneratorMethodIfWrapped 方法调用不兼容 窗口
chrome 中的错误
Uncaught TypeError: Method [Generator].prototype.next 调用 接收器不兼容# 在下一个()
node.js 中的错误
timers.js:475
timer._onTimeout();
^
TypeError: Method [Generator].prototype.next called on incompatible receiver #<Timeout>
at Timeout.next [as _onTimeout] (<anonymous>)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
【问题讨论】:
-
setTimeout(function(){ y.next(); }, 100)怎么样?
标签: javascript node.js es6-generator