久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

JavaScript 中的 const 和 const {} 有什么區別

What is the difference between const and const {} in JavaScript(JavaScript 中的 const 和 const {} 有什么區別)
本文介紹了JavaScript 中的 const 和 const {} 有什么區別的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在學習electron的時候,發現了兩種獲取BrowserWindow對象的方法.

When I study electron, I found 2 ways of getting BrowserWindow object.

const {BrowserWindow} = require('electron')

const electron = require('electron')
const BrowserWindow = electron.BrowserWindow

JavaScript中的constconst {}有什么區別?

What is the difference between const and const {} in JavaScript?

我不明白為什么 const {} 可以工作.我錯過了關于 JS 的任何重要內容嗎?

I can't understand why the const {} can work. Do I miss anything important about JS?

推薦答案

兩段代碼是等價的,但第一段使用的是 ES6 解構賦值 要更短.

The two pieces of code are equivalent but the first one is using the ES6 destructuring assignment to be shorter.

下面是一個簡單的例子來說明它是如何工作的:

Here is a quick example of how it works:

const obj = {
  name: "Fred",
  age: 42,
  id: 1
}

//simple destructuring
const { name } = obj;
console.log("name", name);

//assigning multiple variables at one time
const { age, id } = obj;
console.log("age", age);
console.log("id", id);

//using different names for the properties
const { name: personName } = obj;
console.log("personName", personName);

這篇關于JavaScript 中的 const 和 const {} 有什么區別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 国产一区二区三区久久久久久久久 | 国产精品视频不卡 | 国产一区二区精品在线观看 | 久久国产精品久久久久 | 欧美天堂 | 天堂中文av| 国产一区二区三区久久久久久久久 | 嫩草视频在线免费观看 | 久久久久久综合 | 久久国产精品99久久久久久丝袜 | 日韩欧美国产成人一区二区 | 九九热精品免费 | 免费视频一区 | 99热这里都是精品 | 日韩在线观看 | 中文字幕在线观看日韩 | 国产在线精品一区 | 日本一区二区三区免费观看 | 一级片片 | 91精品国产91综合久久蜜臀 | 在线免费观看视频你懂的 | 瑟瑟视频在线看 | 午夜日韩 | 国产在线中文字幕 | 亚洲午夜精品一区二区三区他趣 | 北条麻妃国产九九九精品小说 | 国产成人网| 欧美综合一区 | 国产精品久久久久久久免费大片 | 在线婷婷 | 国产三区在线观看视频 | 午夜小视频在线播放 | 国产午夜精品一区二区三区四区 | 国产亚洲精品一区二区三区 | 日本在线视频中文字幕 | 国产免费va | 日韩三级 | 99精品一区二区 | 亚洲欧美aⅴ | 中文字幕一区二区三区四区不卡 |