当前位置:网站首页>ES6 new - function part
ES6 new - function part
2022-07-27 09:10:00 【Cabbage 007】
1, grammar :const Function name = () => { }
3. Be careful : Cannot pass new Key word call
4, application : It is mostly used in callback functions and changes this When pointing
Function extension
1.es6 Parameter extension :
(1) The default value is
In the default position of formal parameters , Assign value by single equal sign , Only the parameters are not transmitted and the parameters are undefined Go to the default value
function add(x=10,y=20){ return x+y }
console.log(add(10,10)) //20
console.log(add(' ',0)) // " 0 "
console.log(add(undefined,10)) //20
(2) Variable parameters
...args Collect the remaining parameters args: Parameter name
Be careful : ...args True array ,es5 in arguments Is a pseudo array
Be careful :... Only once ; ... It can only be placed in the last formal parameter position ; ... There can be one or more fixed position parameters in front
function getSum(...args){ console.log(args) }
console.log(1,2,3,4,5) // Output [1,2,3,4,5]
function getArr( ...args,...rest){} // Two ... At the same time , Will report a mistake
function getSum(num,..args){ console.log(num,args)}
console.log(gerSum(100,1,2,3,4,5)) // Output :100,[1,2,3,4,5]
2.es6 New arrow function in
1, grammar :const Function name = () => { }
2. characteristic :
(1) When there is only one formal parameter , You can omit parentheses
(2) When the function body has only one sentence , You can omit the braces , If braces are omitted , Arrow function comes with return function , No more writing
(3) Inside the arrow function this Points to this
3. Be careful : Cannot pass new Key word call
4, application : It is mostly used in callback functions and changes this When pointing
Ordinary function const fu = function(){ }
Arrow function const fn=()=>{ The body of the function } fn()
const sayHi = function(name){ return `hi${this.name}`}
const sayHi = (name)=>{ `hi${this.name}` } sayHi("aa")
边栏推荐
- Save Xiaoyi from Netease written test -- a typical application of Manhattan distance
- flex布局 (实战小米官网)
- CUDA programming-02: first knowledge of CUDA Programming
- 如何在B站上快乐的学习?
- Test picture
- 500 error reporting
- Built in method of tensorflow model training and evaluation
- Deep understanding of Kalman filter (1): background knowledge
- Interface test tool -postman usage details
- 软件测试功能测试全套常见面试题【功能测试-零基础】必备4-1
猜你喜欢

巴比特 | 元宇宙每日必读:广州南沙发布“元宇宙九条”措施,平台最高可获得2亿元资金支持...

5G没能拉动行业发展,不仅运营商失望了,手机企业也失望了

PVT's spatial reduction attention (SRA)

B tree

flex布局 (实战小米官网)

CUDA programming-05: flows and events

5g failed to stimulate the development of the industry, which disappointed not only operators, but also mobile phone enterprises

【微服务~Sentinel】Sentinel之dashboard控制面板
![[I2C reading mpu6050 of Renesas ra6m4 development board]](/img/1b/c991dd0d798edbb7410a1e16f3a323.png)
[I2C reading mpu6050 of Renesas ra6m4 development board]

音乐体验天花板!14个网易云音乐的情感化设计细节
随机推荐
5G没能拉动行业发展,不仅运营商失望了,手机企业也失望了
【微服务~Sentinel】Sentinel之dashboard控制面板
Detailed explanation of two methods of Sqlalchemy
Matlab uses m file to produce fuzzy controller
ArkUI框架中的两个小技巧
500 error reporting
Huawei machine test question: Martian computing JS
08_ Service fusing hystrix
MySQL基础知识学习(一)
Solve the problem of Chinese garbled code on the jupyter console
CUDA programming-05: flows and events
Cross domain and processing cross domain
Encountered 7 file(s) that should have been pointers, but weren‘t
拍卖行做VC,第一次出手就投了个Web3
QT uses SQLite to open multiple database files at the same time
How to study happily on station B?
Unity3d 2021 software installation package download and installation tutorial
ArkUI开发框架组件的生命周期
Specific methods and steps for Rockwell AB PLC to establish communication with PLC through rslinx classic
Antdesign a-modal自定义指令实现拖拽放大缩小