在阅读使用 electron 制作软件的文档时,我在 index.js 文件(一般执行开始的文件)
While reading docs of making softwares with electron, I came across this type of code in the beginning of index.js file (the file where generally execution starts)
const {app, BrowserWindow} = require('electron')
{app, BrowserWindow}(语法,而不是关键字)的真正含义是什么?它是 JavaScript 语法,还是 node.js 的东西,还是与电子相关的东西?
What does {app, BrowserWindow} (the syntax, not the keywords) really means? Is it a JavaScript syntax, or a node.js thing or something exclusively related to electron?
这种语法称为对象解构",它是最新版本的 JavaScript(JavaScript2015 aka ECMAScript 6/ES6)的一个特性 - app 和 BrowserWindow 只是您希望在应用程序的这一部分中使用的 electron 的特定部分.
This syntax is called 'object destructuring', and it is a feature of the latest version of JavaScript (JavaScript2015 aka ECMAScript 6/ES6) - app and BrowserWindow are just particular parts of electron that you want to use in this portion of your application.
这是一种简化代码并轻松引用依赖项关键部分的方法.
It's a way to simplify your code and to easily reference critical parts of a dependency.
这是 https:///developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
var o = {p: 42, q: true};
var {p, q} = o;
console.log(p); // 42
console.log(q); // true
所以在你的例子中,electron 是一个导入的模块,看起来像(同样,这里过于简单化了):
So in your case, electron is an imported module that would look something like (again, a gross oversimplification here):
var electron = {
app: {
greet: () => {
console.log("Hello, world!")
}
},
BrowserWindow: {/* some other stuff *
在 Electron 渲染器进程中创建子窗口时如何修复How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器进程中创建子窗口
mainWindow.loadURL("https://localhost:3000/") 在 EmainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 应用程
Electron webContents executeJavaScript:无法在第二个 loaElectron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:无法在第二个 loadURL 上
如何在angular-cli的组件内使用电子浏览器窗口?how to use electron browser window inside components in angular-cli?(如何在angular-cli的组件内使用电子浏览器窗口?)
ElectronJS - 在 Windows 之间共享 redux 存储?ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之间共享 redux 存储?)
如何在电子应用程序中访问相机/网络摄像头?How to access camera/webcamera inside electron app?(如何在电子应用程序中访问相机/网络摄像头?)