且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

破坏还是有所不同?

更新时间:2023-09-18 23:41:10

您可以考虑

const {getElementById, seedElements} = require('./utils')

由于导出后发生的破坏性变化,您将导出内容写为

as destructuring since when you export, you would write your export like

module.exports = { getElementById, seedElements };

export { getElementById, seedElements };

并且在使用require进行导入时,您基本上将导入整个模块,并且可以从中解构单个模块.

and while importing using require you would basically be importing the entire module and you can destructure the individual modules from it.

const {getElementById, seedElements} = require('./utils')

将类似于

const Utils = require('./utils');
const { getElementById, seedElements } = Utils;

使用导入语法,但是您将导入命名的导出,例如

with the import syntax, you would however import the named exports like

import { getElementById, seedElements } from './utils';