【新提案】获取for/for await的return值 #51
Unanswered
LongTengDao
asked this question in
Ideas
Replies: 1 comment
-
去年 iterator helpers 提案的讨论决定 iterator helpers 不考虑 generator 协议在单纯 iterator 协议之外的额外语义,如 另一个问题是,for-of(以及所有的循环结构)虽然并不是表达式,但作为语句也是有值的,可以通过 eval 来得到。其语义为循环体中最后一个语句的值(如果没有则为 const v = eval(` for (const each of [1, 2]) { 42 } `)
v // 42 因此如果要允许 for-of 成为表达式,其值的语义恐怕也很难改变。 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
时不时需要获知return值,目前就得额外参数通信,或者改成手动调用next,很不方便。
Beta Was this translation helpful? Give feedback.
All reactions