Javascript中的经典脚本v / s模块脚本 [英] Classic scripts v/s module scripts in Javascript

查看:131
本文介绍了Javascript中的经典脚本v / s模块脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 async 的WHATWG规范和延迟属性< ; script> 标签,当我看到这句话时:

I was going through the WHATWG specs for async and defer attributes for the <script> tag, when I saw this statement:


经典脚本可以指定延期异步; 模块脚本可以指定 async

Classic scripts may specify defer or async; module scripts may specify async.

我浏览了经典模块<的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.

来自§8.1.3.8与JavaScript模块系统的集成


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 with type 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆