当前位置:网站首页>ES6 syntax extension
ES6 syntax extension
2022-07-29 02:16:00 【weixin_ forty-seven million two hundred and fifty-four thousand】
Writing time :2022 year 7 month 27 Japan
ES6 Grammar extension
The remaining parameters :
Recognize the remaining parameters :
const add=(x,y,z,…arg)=>{};
Essence of residual parameters ===> The remaining parameters are always an array , Even if there is no value, it is an empty array
const add = (x, y, …arg) => {
console.log(x, y, arg);
}
add(2, 3, 5, 6);// x=2 y=3 arg=[5,6]
The default values of the remaining parameters
1. The remaining parameters of the arrow function
The parameter part of the arrow function, even if there is only one remaining parameter , You can't omit parentheses :
const add=(…arg)=>{}
2. Use the remaining parameters instead of arguments Get actual parameters :
const add = function () {
// arguments Is a class array object
console.log(arguments);
}
add(1, 2);
const add = (…arg) => {
// Not in arrow function arguments object
// You can use the remaining parameters arg Instead of arguments
console.log(arg);// arg Is an array
}
add(1, 2);
3. The location of the remaining parameters
The remaining parameter can only be the last parameter , After that, there can be no other parameters , Otherwise, an error will be reported :
const add=(x,y,z,…arg)=>{};
Application of remaining parameters :
1. complete add function
const add = (…arg) => {
let sum = 0;
for (let i = 0; i < array.length; i++) {
sum += arg[i];
}
return sum;
}
add(1, 2, 4, 4, 6, 7, 6)
2. In combination with deconstruction assignment
The remaining parameters do not have to be used as parameters of the function
// Must be the last parameter
const [num, …args] = [2, 3, 5, 6, 7];
//const […args,num ] = [2, 3, 5, 6, 7];// Report errors
console.log(num, args);//args = [3,5,6,7]
// The remaining elements z Combine deconstruction objects z It can also be an object
const { x, y, …z } = { x: 3, a: ‘a’, b: ‘b’, y: 2 };
console.log(z);//z={a: “a”,b: “b”}
// Deconstruction of function parameters
const func = ({ x, y, …z }) => {
console.log(z);//z={a: “a”,b: “b”}
}
func({ x: 3, a: ‘a’, b: ‘b’, y: 2 })
边栏推荐
- JS dom2 and dom3
- [electronic components] constant voltage, amplify the current of the load (triode knowledge summary)
- 2022.7.27-----leetcode.592
- iVX低代码平台系列详解 -- 概述篇(二)
- 表单校验 隐藏的输入框 显示才校验
- 年中总结 | 与自己对话,活在当下,每走一步都算数
- 第十五天(VLAN相关知识)
- [UE4] replay game playback for ue4.26
- “蔚来杯“2022牛客暑期多校训练营2,签到题GJK
- Mobile communication -- simulation model of error control system based on convolutional code
猜你喜欢

Navigation -- realize data transmission and data sharing between fragments

MotionLayout--在可视化编辑器中实现动画

Basic working principle and LTSpice simulation of 6T SRAM

Rgbd point cloud down sampling

2022年编程语言排名,官方数据来了,让人大开眼界
![[electronic components] constant voltage, amplify the current of the load (triode knowledge summary)](/img/07/d5861404a76a0fb7d6d5f930a4a66a.png)
[electronic components] constant voltage, amplify the current of the load (triode knowledge summary)

物联网开发--MQTT消息服务器EMQX

Using local cache + global cache to realize user rights management of small systems

什么是作用域和作用域链

Blind separation of speech signals based on ICA and DL
随机推荐
Add graceful annotations to latex formula; "Data science" interview questions collection of RI Gai; College Students' computer self-study guide; Personal firewall; Cutting edge materials / papers | sh
Comprehensive use method of C treeview control
2022年编程语言排名,官方数据来了,让人大开眼界
向量相似度评估方法
Leetcode 242. valid anagram
Click back to the top JS
Promise solves asynchrony
Mathematical modeling -- Optimization of picking in warehouse
Force deduction brush question (2): sum of three numbers
Idea connection database
物联网开发--MQTT消息服务器EMQX
iVX低代码平台系列详解 -- 概述篇(二)
The problem of modifying the coordinate system of point cloud image loaded by ndtmatching function in autoware
JVM内存溢出在线分析Dump文件以及在线分析打开.hprof文件得出JVM运行报告jvisualvm怎么在线分析
C语言提高篇(一)
MySQL stores JSON format data
Control buzzer based on C51
What is browser fingerprint recognition
基于C51控制蜂鸣器
Mathematical modeling - location of police stations