在ES6中使用导入导出时,我收到以下错误:
SyntaxError:export声明只能出现在顶层
我冲浪找到如何解决这个问题,但我无法解决.任何人都可以解释一下.我是ES6的新手,特别是进口和出口.(我完全使用StealJS来做这种事情)谢谢!
js文件是:
app.js
import { cube, cubeRoot } from 'functions';
console.log(cube(4));
console.log(cubeRoot(125));
Run Code Online (Sandbox Code Playgroud)
functions.js
// functions.js
function cube(a) {
return a * a * a;
}
function cubeRoot(a) {
return Math.cbrt(a);
}
export { cube, cubeRoot}
Run Code Online (Sandbox Code Playgroud) 我在Mozilla Dev页面中查看生成器函数.
有一个示例代码具有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)
Run Code Online (Sandbox Code Playgroud)
但是,chrome和Firefox(最新版本)都在send()函数上抛出错误.
对此有何看法?它不受支持吗?