Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import nested objects in ES6

Tags:

javascript

Simple question, I'm trying to use electron and I need to get the remote object on the client.

Doing

const {BrowserWindow} = require('electron').remote; // Works

But

import {BrowserWindow} from 'electron/remote' // Does not work

New to ES6 classes just unsure why this is not working. Thanks.

like image 571
Datsik Avatar asked Oct 05 '16 11:10

Datsik


People also ask

Can you nest objects in JavaScript?

The basic definition of an object in JavaScript is a container for named values called properties (keys). Sometimes, we need to create an object inside another object. In this case, it's called a nested object.

What is import in ES6?

Introduction to ES6 import:The import statement is used to import modules that are exported by some other module. A module is a file that contains a piece of reusable code. The import modules are in strict mode whether it is declared or not.

What is module in ES6?

Modules are the piece or chunk of a JavaScript code written in a file. JavaScript modules help us to modularize the code simply by partitioning the entire code into modules that can be imported from anywhere. Modules make it easy to maintain the code, debug the code, and reuse the piece of code.

How many parts are there in an ES6 module?

The ES6 module standard has two parts: Declarative syntax (for importing and exporting) Programmatic loader API: to configure how modules are loaded and to conditionally load modules.


1 Answers

You can only import from modules. electron/remote is not a module, but remote is part of the module electron, so you can write :

import remote from "electron";

And then you can do :

const {BrowserWindow} = remote;

But your first code works fine ! You can read more on import statement here

Hope this helps

like image 118
Richard Casetta Avatar answered Sep 28 '22 18:09

Richard Casetta