Javascript中的经典脚本v / s模块脚本 [英] Classic scripts v/s module scripts in Javascript
问题描述
我正在通过 async
的WHATWG规范和延迟
属性< ; script>
标签,当我看到这句话时:
I was going through the WHATWG specs for async
and defer
attributes for the <script>
tag, when I saw this statement:
Classic scripts may specify
defer
orasync
; module scripts may specifyasync
.
我浏览了经典和模块<的WHATWG定义/ strong>脚本,但并没有真正清晰。有人可以向我解释我是5,Javascript中经典和模块脚本之间的区别吗?
I went through the WHATWG definitions for classic and module scripts, but didn't really get much clarity. Could someone explain to me like I'm 5, the differences between classic and module scripts in Javascript?
推荐答案
经典脚本只是您所知道的标准JavaScript脚本。 模块脚本包含 ES6模块,即它使用(或:可以使用) import
和 export
声明。
A classic script is just a standard JavaScript script as you know it. A module script is one that contains an ES6 module, i.e. it uses (or: can use) import
and export
declarations.
JavaScript规范定义了模块的语法作为
他们的处理模型的一些与主机无关的部分。此规范
定义了其处理模型的其余部分:模块系统是如何通过带有类型的
属性设置为脚本
元素进行
bootstrapped
module
,以及如何获取,解析和执行模块。
[JAVASCRIPT]
The JavaScript specification defines a syntax for modules, as well as some host-agnostic parts of their processing model. This specification defines the rest of their processing model: how the module system is bootstrapped, via the
script
element withtype
attribute set to"module"
, and how modules are fetched, resolved, and executed. [JAVASCRIPT]
注意:尽管JavaScript规范以脚本与模块的形式对话,但一般来说,这个规范用$ a bref表示经典脚本
与模块脚本,
,因为它们都使用脚本元素。
Note: Although the JavaScript specification speaks in terms of "scripts" versus "modules", in general this specification speaks in terms of classic scripts versus module scripts, since both of them use the script element.
另请参阅 https://blog.whatwg.org / js-modules 。
这篇关于Javascript中的经典脚本v / s模块脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!