Files
Nicholas Carrigan (he/him) 3da4be21bb chore: seed chinese traditional (#42005)
Seeds the chinese traditional files manually so we can deploy to
staging.
2021-05-05 22:43:49 +05:30

1.7 KiB
Raw Permalink Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
5cddbfd622f1a59093ec611d 創建一個模塊腳本 6 301198 create-a-module-script

--description--

起初JavaScript 幾乎只在 HTML web 扮演一個很小的角色。 今天,一切不同了,很多網站幾乎全是用 JavaScript 所寫。 爲了讓 JavaScript 更模塊化、更整潔以及更易於維護ES6 引入了在多個 JavaScript 文件之間共享代碼的機制。 它可以導出文件的一部分供其它文件使用,然後在需要它的地方按需導入。 爲了使用這一功能, 需要在 HTML 文檔裏創建一個 typemodule 的腳本。 例子如下:

<script type="module" src="filename.js"></script>

使用了 module 類型的腳本可以使用 importexport 特性(接下來的挑戰會介紹)。

--instructions--

給 HTML 文檔添加 module 類型的腳本,指定源文件爲 index.js

--hints--

應該創建一個 script 標籤。

assert(code.match(/<\s*script[^>]*>\s*<\/\s*script\s*>/g));

script 標籤應該有一個值爲 moduletype 屬性。

assert(
  code.match(
    /<\s*script\s+[^t]*type\s*=\s*('|")module\1[^>]*>\s*<\/\s*script\s*>/g
  )
);

script 標籤的 src 屬性應該爲 index.js

assert(
  code.match(
    /<\s*script\s+[^s]*src\s*=\s*('|")index\.js\1[^>]*>\s*<\/\s*script\s*>/g
  )
);

--seed--

--seed-contents--

<html>
  <body>
    <!-- Only change code below this line -->

    <!-- Only change code above this line -->
  </body>
</html>

--solutions--

<html>
  <body>
    <script type="module" src="index.js"></script>
  </body>
</html>