ecmascript-6 - ES6 中的生成器
问题描述
我有代码:
function countA() {
return 1;
}
function* sendStuff() {
let y = yield countA();
console.log("y: ", y);
yield;
}
var gen = sendStuff();
console.log(gen.next().value);
console.log(gen.next().value);
结果是:
> 1
> "y: " undefined
> undefined
为什么 y 未定义?我知道我应该是 1(从 countA 结果中获取)。请帮帮我。十分感谢
解决方案
推荐阅读
- mysql - 如何在mysql中更新多个表中的多行
- python - 如何为我的 PyCharm Python 项目安装 yaml 包?
- square - “授权码已被认领”错误
- node.js - Angular 7 和 Nodejs 的验证表单问题
- db2 - 在 DB2 SQL 中,如何使用 FETCH FIRST (n) ROWS ONLY..返回可变数量的行?
- java - 如何解决安装pycharm后出现的启动错误?
- ios - wkwebview 链接在点击时不会打开
- node.js - MongoParseError:在 parseConnectionString 处未转义的登录权限部分
- sql - 如何使用 SQL 在开始日期和结束日期之间拆分值?
- r - 将来指定多进程计划的惯用、灵活的方式是什么?