按照阮一峰的ECMA6标准入门例子写的,运行环境为vscode
"use strict"
function* fibs() {
let a = 0;
let b = 1;
while (true) {
yield a;
[a, b] = [a, a+b];
}
}
let [first, second, third, fourth, fifth, sixth] = fibs();
console.log(sixth)
运行报错,报错为
[a, b] = [a, a+b];
^
ReferenceError: Invalid left-hand side in assignment
有知道为什么的大牛吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你好像写错了。
应该是
[a, b] = [b, a + b]这里是迭代过程,先把当前的
b赋值给a,然后把当前的a + b赋值给b相当于这样的写法:
很明显,你的环境不支持ES6