問題描述
在閱讀使用 electron 制作軟件的文檔時(shí),我在 index.js
文件(一般執(zhí)行開始的文件)
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}
(語(yǔ)法,而不是關(guān)鍵字)的真正含義是什么?它是 JavaScript 語(yǔ)法,還是 node.js 的東西,還是與電子相關(guān)的東西?
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?
推薦答案
這種語(yǔ)法稱為對(duì)象解構(gòu)",它是最新版本的 JavaScript(JavaScript2015 aka ECMAScript 6/ES6)的一個(gè)特性 - app
和 BrowserWindow
只是您希望在應(yīng)用程序的這一部分中使用的 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.
這是一種簡(jiǎn)化代碼并輕松引用依賴項(xiàng)關(guān)鍵部分的方法.
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
是一個(gè)導(dǎo)入的模塊,看起來像(同樣,這里過于簡(jiǎn)單化了):
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 *
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!