ES6 解构赋值 All In One
1.如何使用 js 实现一个 ES6 中 class 的 extends 功能 All In One2.ECMAScript 2023 & Temporal All In One3.js ES5 arguments & arguments.callee & this & ES6 new.target All In One4.ES6 Map Object index All In One5.TypeScript Decorator Metadata All In One6.js ES6 Proxy All In One7.js ES6 Reflect All In One8.js @decorator All In One9.Vue warn All In One
10.ES6 解构赋值 All In One
11.ES6 & export & export default All In One12.ES6 Async Await bug All In One13.ES6 destructuring assignment & default value & rename All In One14.ES6 Symbol All In One15.ES6 Map & WeakMap All In One16.ES6 Reflect All In One17.ES6 Proxy & Reflect All In One18.composition-api & setup19.ES6 Arrow Function & this bug20.ES5 arguments vs ES6 ...rest params All In One21.ES6 export & export.default All In One22.es6 string html23.js create Array ways All In One24.ES6 version repeatify25.es6 curry function26.JavaScript convert ES6 Map to Array All In One27.JavaScript string repeat methods All In One28.ES6 Set All In One29.ES6 Map All In One30.ES6 Arrow Function All In One31.如何用 js 实现一个 ES6 class 类函数 All In One32.ES6 进制字面量 All In One33.redux 中间件 redux-saga 使用教程34.how to convert Map to Object in js35.ES6 Set vs ES5 Array36.ES6 getter & setter37.ES6 arrow function vs ES5 function All In One38.ES6 Class vs ES5 constructor function All In One39.ES6 Generator vs ES6 async/await40.ES6 Map vs ES5 Object All In One41.js swap array42.ES6 ...rest In Action43.Webpack 4.x 默认支持 ES6 语法44.2020 面经(大前端,算法,设计模式,架构)45.js ES5 inheritance All In One46.JavaScript Learning Paths(ES5/ES6/ES-Next)47.ES5 function & ES6 class & method type48.Unicode & \u2028 & \u2029 & ES6 Template literals All In One49.random array & shuffle 洗牌算法 / 随机算法50.js in depth: ES6 destructuring assignment51.gradient text & gradient background52.V8 & ECMAScript & ES-Next53.js 数据劫持 (应用场景) All In One54.ES6 Arrow Function return Object55.ES6 Class & super All In One56.ES6 & tagged-template-literals & template strings All In One57.Enums & JavasScript & TypeScript58.es6 & map & set59.ES6 & import * & import default & import JSON All In One60.vue @ path61.ES6 & Classes & Interface62.ES6 & class extends All In One63.Google Advanced Search operators All In One64.React Native & ES6 & emoji All In One65.ES6 & Map & hashMap66.array to object67.ES6 Set & Map68.ES6 Destructuring Assignment All In One69.vue & lifecycle methods & this bug & ES6 Arrow function & this bind bug70.HTML Imports & polyfill71.yarn & vue-cli & hui-cli All In One72.ES6 Map & WeakMap & ES6 Set & WeakSet73.ES6 polyfills & String.includes() & Array.includes()74.ES6 Arrow Function & this bug75.ES6 Proxies76.ES6 import json77.disable VS Code auto format javascript when save codes78.how to create a javascript components framework using HTML5, CSS3, ES6 All In One79.eslint es6 syntax & object rest spread80.!function() & IIFE81.React.createClass vs. ES6 Class Components82.ES2015 (ES6) 新特性: 20 个ES6 解构赋值 All In One
解构赋值
JavaScript 中最常用的两种数据结构是 Object 和 Array。
对象让我们能够创建通过键来存储数据项的单个实体,数组则让我们能够将数据收集到一个有序的集合中。
但是,当我们把它们传递给函数时,它可能不需要一个整体的对象/数组,而是需要单个块。
解构赋值 是一种特殊的语法,它使我们可以将数组或对象“拆包”为到一系列变量中,因为有时候使用变量更加方便。
解构操作对那些具有很多参数和默认值等的函数也很奏效。
优缺点
解构赋值是对赋值运算符的扩展。
他是一种针对数组或者对象进行模式匹配,然后对其中的变量进行赋值。
在代码书写上简洁且易读,语义更加清晰明了;也方便了复杂对象中数据字段获取。
- 简洁且易读
async getBlockData () {
this.initChart();
this.localData = [];
this.chartLoading = true;
const params = this.getParams();
const res = await Table2DataGlobalService.getRealtimeData(this.apiType, params).finally(() => {
this.chartLoading = false;
});
// console.log('res =', res,);
// console.log('res.data =', res.data);
const {
data: {
data: rows,
last_updated,
meta: {
starttime,
endtime,
},
},
} = res;
this.localData = rows;
this.chartsData1 = this.formatChartData(rows, this.appType);
this.chartsData2 = this.formatChartData(rows, this.payType);
if (last_updated) {
// 日期转换
this.lastUpdateTime = this.$dayjs(last_updated).format('YYYY年MM月DD日 HH:mm');
}
},
this.filterData
. shit 💩 ❌👎
getParams () {
// return {
// starttime: '2021-07-24',
// endtime: '2021-07-30',
// game_id: 10043,
// store_id: '',
// region_id: '',
// app_id: '',
// filter_fraud: 1,
// tz: 8,
// };
return {
starttime: this.filterData.starttime,
endtime: this.filterData.endtime,
game_id: this.filterData.gameId,
store_id: this.filterData.storeId,
region_id: this.filterData.regionIds,
app_id: this.filterData.packageIds,
filter_fraud: this.filterData.isFraud,
tz: this.filterData.timezone,
};
},
TL 不要使用 ES6 解构赋值,不符合团队规范,代码维护性差 ???
WTF, SB 💩
refs
https://zh.javascript.info/destructuring-assignment
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15224955.html
未经授权禁止转载,违者必究!
合集:
ES6
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2020-09-03 TypeScript LeetCode 面试题 All In One
2020-09-03 JavaScript & Atomics
2020-09-03 Web Components All In One
2020-09-03 Express vs Koa
2020-09-03 Open Collective
2020-09-03 window.ShadyCSS
2020-09-03 NGINX configure auto generator