我正在考虑从Dart转向ES6,但是Chrome似乎不支持对我至关重要的新导入语句。
我使用了来自这个网站(http://www.2ality.com/2014/09/es6-modules-final.html)的(命名导出)代码。
我甚至尝试过它。
<module import="main"><module>
我遇到了错误:“Unexpected token import”
他们会在最终版本之前支持它吗?
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>ES6</title>
</head>
<body bgcolor="blue">
<script type="module" src="main.js"></script>
</body>
</html>
主要.js文件
import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5
lib.js:
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
}