gpt4 book ai didi

ecmascript-6 - 尝试使用 Chrome 导入 ES6,但似乎不起作用

转载 作者:行者123 更新时间:2023-12-03 21:52:07 24 4
gpt4 key购买 nike

我正在考虑从 Dart 迁移到 ES6,但 Chrome 似乎不支持对我来说至关重要的新 import 语句。

我使用了这个站点的(命名导出)代码:http://www.2ality.com/2014/09/es6-modules-final.html

我试过了

<module import="main"><module>

我收到错误消息:“意外的 token 导入”

在最终发布之前他们是否会支持它的任何信息?

代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>ES6</title>
</head>
<body bgcolor="blue">
<script type="module" src="main.js"></script>
</body>
</html>

主文件
import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5

库.js:
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
}

最佳答案

它现在可以工作了,终于在启用了实验性 Web 平台功能的 Chrome 60 中运行了。

这是一个测试:
https://github.com/paulirish/es-modules-todomvc

在这里查看状态新闻:
https://www.chromestatus.com/features/5365692190687232

关于ecmascript-6 - 尝试使用 Chrome 导入 ES6,但似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35496479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com