Jun*_*ang 7 javascript es6-modules
对于对象const a = {b: 1, c: 2, d: 3},我们可以做解构这样的:const {b, ...rest} = a。
我想知道imports是否也可以。
说我有一个文件file1.js:
// file1.js
export const a = 1;
export const b = 2;
export const c = 3;
Run Code Online (Sandbox Code Playgroud)
我可以通过导入一个和其他像解构一样从这个文件导入吗?
// file2.js
import {a, ...rest} from "file1";
Run Code Online (Sandbox Code Playgroud)
不直接,没有import形式。
您可以做的是导入模块的模块命名空间对象,然后对其使用解构:
import * as file1 from "file1";
const {a, ...rest} = file1;
Run Code Online (Sandbox Code Playgroud)
FWIW,该规范在此处提供了import表单示例列表。它没有显示您可以组合和不能组合的内容,但这些是基本形式。
| 归档时间: |
|
| 查看次数: |
279 次 |
| 最近记录: |