破坏还是有所不同? [英] Destructuring or Something Different?

查看:50
本文介绍了破坏还是有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来像是解构:

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

但是我对此感到困惑.我曾经看到过类似的东西:

but I'm confused about it. I'm used to seeing something like:

let {first, last} = name

这些文件是否只是在不同的文件中执行相同的操作?

Are these doing the same things just in different files?

推荐答案

您可以考虑

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';

这篇关于破坏还是有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆