相当于在ES6导入中需要子属性 [英] Equivalent of requiring a subproperty in ES6 import

查看:146
本文介绍了相当于在ES6导入中需要子属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现有需要

const {dialog} = require('electron').remote;

我开始使用Babel for ES6,并希望 import 相反。到目前为止,我有:

I started using Babel for ES6, and would like to import this instead. So far I have:

import electron from 'electron';
const {dialog} = electron.remote;

这很难看,我不禁觉得有更好的方法可以做到这一点。我只是需要此处的对话框。我如何在一行中获得它?

This is ugly, and I can't help but feel there is a better way to do this. I just need the dialog here. How do I get at it in one line?

推荐答案

ECMAScript模块语法不允许深度解构。事实上,它根本不会破坏。 Import语句在模块之间创建实时绑定。

ECMAScript module syntax doesn't allow deep destructuring. In fact it doesn't destructure at all. Import statements create live bindings between modules.

这是由Ben Nadel撰写的精彩博客文章。它应该对绑定有所了解: http://www.bennadel.com/blog/3131-the-import-statement-creates-a-live-view-of-modules-in -es6-and-typescript-in-angular-2.htm

Here is great blog post written by Ben Nadel. It should shed some light on bindings: http://www.bennadel.com/blog/3131-the-import-statement-creates-a-live-view-of-modules-in-es6-and-typescript-in-angular-2.htm

这样做

import electron from 'electron';
const {dialog} = electron.remote;

电子就是这种绑定。通过进行解构赋值对话框是常规常量,它不会绑定到电子模块(它不会更新)。

electron is such binding. By doing destructuring assignment dialog is normal constant and it won't be "bound" to electron module (it won't update).

这篇关于相当于在ES6导入中需要子属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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