import

您所在的位置:网站首页 errorpagestringsjs import

import

2023-03-27 03:45| 来源: 网络整理| 查看: 265

import declarations can only be present in modules, and only at the top-level (i.e. not inside blocks, functions, etc.). If an import declaration is encountered in non-module contexts (for example, tags without type="module", eval, new Function, which all have "script" or "function body" as parsing goals), a SyntaxError is thrown. To load modules in non-module contexts, use the dynamic import syntax instead.

import declarations are designed to be syntactically rigid (for example, only string literal specifiers, only permitted at the top-level, all bindings must be identifiers), which allows modules to be statically analyzed and linked before getting evaluated. This is the key to making modules asynchronous by nature, powering features like top-level await.

There are four forms of import declarations:

Named import: import { export1, export2 } from "module-name"; Default import: import defaultExport from "module-name"; Namespace import: import * as name from "module-name"; Side effect import: import "module-name";

Below are examples to clarify the syntax.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3