gpt4 book ai didi

es6 导入和导出中的模块说明符

转载 作者:行者123 更新时间:2023-12-04 03:10:43 26 4
gpt4 key购买 nike

我对这些语句中的模块说明符所指的内容感到困惑:

export {bar} from "foo";

import {bar} from "foo";
"foo" 是什么意思引用?它不能是文件,因为它类似于 "./foo" .如果它不是一个文件,我认为它是一个 ID。 ID是如何定义的?

我正在从 js 文件导出,但导入将是 firefox 浏览器中内联 html 脚本 ( type="module" ) 的一部分。

浏览器版本(和浏览器设置)已经过验证,可以与 es6 模块一起使用。

提前致谢。

最佳答案

ES6 没有指定模块说明符所指的内容。
确实就是这样:一个标识符。而已。

由环境将这些标识符解析为实际模块。加载器可能会将它们解释为相对文件路径、全局 id、npm 模块名称或其他任何内容。

在浏览器中, <script type="module"> took some time to specify ,但它终于来了。 "foo" 的模块说明符当前无效,浏览器将忽略该模块,因为它不知道如何处理它。它将需要解析为要加载的 URL 的内容。 jack ·阿奇博尔德 wrapped it up succinctly :

"Bare" import specifiers aren't currently supported. Valid module specifiers must match one of the following:

  • A full non-relative URL. As in, it doesn't throw an error when put through new URL(moduleSpecifier).
  • Starts with /.
  • Starts with ./.
  • Starts with ../.

Other specifiers are reserved for future-use, such as importing built-in modules.

关于es6 导入和导出中的模块说明符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44930637/

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