From 867a9aae2b7e54eca0099c6f5d103d0ef171f6f4 Mon Sep 17 00:00:00 2001 From: Kevin CHEN <33132228+KevinZonda@users.noreply.github.com> Date: Wed, 18 Aug 2021 15:38:14 +0100 Subject: Fix syntax highlight Web/JavaScript/Reference/Statements/import, zh-CN (#2110) * optimise Statements/import * http -> https * remove code tag in pre --- .../javascript/reference/statements/import/index.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'files/zh-cn') diff --git a/files/zh-cn/web/javascript/reference/statements/import/index.html b/files/zh-cn/web/javascript/reference/statements/import/index.html index b7634d9cef..203ce9b8cc 100644 --- a/files/zh-cn/web/javascript/reference/statements/import/index.html +++ b/files/zh-cn/web/javascript/reference/statements/import/index.html @@ -21,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Statements/import

语法

-
import defaultExport from "module-name";
+
import defaultExport from "module-name";
 import * as name from "module-name";
 import { export } from "module-name";
 import { export as alias } from "module-name";
@@ -95,7 +95,7 @@ var promise = import("module-name");//这是一个处于第三阶段的提案。
 
 

整个模块仅为副作用(中性词,无贬义含义)而导入,而不导入模块中的任何内容(接口)。 这将运行模块中的全局代码, 但实际上不导入任何值。

-
import '/modules/my-module.js';
+
import '/modules/my-module.js';

导入默认值

@@ -116,9 +116,9 @@ var promise = import("module-name");//这是一个处于第三阶段的提案。 // specific, named imports
-

When importing a default export with {{anch("Dynamic Imports", "dynamic imports")}}, it works a bit differently. You need to destructure and rename the "default" key from the returned object.

+

当用{{anch("动态导入")}}的方式导入默认导出时,其工作方式有所不同。你需要从返回的对象中解构并重命名 "default" 键。

-
(async () => {
+
(async () => {
   if (somethingIsTrue) {
     const { default: myDefault, foo, bar } = await import('/modules/my-module.js');
   }
@@ -140,15 +140,15 @@ var promise = import("module-name");//这是一个处于第三阶段的提案。
 
 

关键字import可以像调用函数一样来动态的导入模块。以这种方式调用,将返回一个 promise

-
import('/modules/my-module.js')
+
import('/modules/my-module.js')
   .then((module) => {
     // Do something with the module.
-  });
+  });
 

这种使用方式也支持 await 关键字。

-
let module = await import('/modules/my-module.js');
+
let module = await import('/modules/my-module.js');

示例

@@ -227,6 +227,6 @@ for (const link of document.querySelectorAll("nav > a")) {
  • Limin Zhu, Brian Terlson and Microsoft Edge Team: Previewing ES6 Modules and more from ES2015, ES2016 and beyond
  • Hacks blog post by Jason Orendorff: ES6 in Depth: Modules
  • Hacks blog post by Lin Clark: ES modules: A cartoon deep-dive
  • -
  • Axel Rauschmayer's book: "Exploring JS: Modules"
  • +
  • Axel Rauschmayer's book: "Exploring JS: Modules"
  • The Modern JavaScript Tutorial(javascript.info): Export and Import
  • -- cgit v1.2.3-54-g00ecf