当前位置:网站首页>Use of arrow function
Use of arrow function
2022-07-27 16:21:00 【Supreme and peerless】
The arrow function is ES6 Then add a method of writing functions , And it's more concise than function expressions .
- Arrow functions are not bound this、arguments attribute ;
- The arrow function cannot be used as Constructors To use
Writing form of arrow function
- () The parameters of the function
- {} The body of the function
nums.forEach((item, index, arr)=>{
})Writing optimization of arrow function
Optimize one : If there is only one parameter () It can be omitted
nums.forEach(item => {})Optimization II : If there is only one line of code in the body of the function , Then you can omit the braces
And the return value of this line of code will be used as the return value of the whole function
nums.forEach(item => console.log(item))
nums.filter(item => true)Optimize three : If the function body returns only one object , So you need to add... To this object ()
var foo = () => {
return { name: "abc" }
}
var bar = () => ({name: "abc"})Case study : Use the arrow function to output the even sum of squares in an array
var nums = [20, 40, 11, 22, 45, 36, 89]
var result = nums.filter(item => item % 2 === 0)
.map(item => item ** 2)
.reduce((preValue, item)=> preValue + item)
console.log(result)边栏推荐
- DRF learning notes (III): model class serializer modelserializer
- Redis简介与使用
- Chapter I Marxist philosophy is a scientific world outlook and methodology
- Security software related to wireless network analysis (airtrack ng)
- Personal perception of project optimization
- 移动端h5常见问题
- Pychart imports the existing local installation package
- DRF learning notes (V): viewset
- Wechat applet personal number opens traffic master
- Pychart import existing project
猜你喜欢

2.2 JMeter基本元件

Nacos

Ncnn reasoning framework installation; Onnx to ncnn

DRF learning notes (IV): DRF view

Keil implements compilation with makefile

无线网络分析有关的安全软件(aircrack-ng)

Nacos

MapReduce instance (II): Average

DRF use: get request to get data (small example)

Content ambiguity occurs when using transform:translate()
随机推荐
The 4.3 billion euro cash acquisition of OSRAM failed! AMS said it would continue to acquire
Scratch crawler framework
Leetcode 226 flip binary tree (recursive)
IO流简介
busybox login: can't execute '/bin/bash': No such file or directory 解决方法
DeFi安全之DEX与AMMs
Six capabilities of test and development
It can carry 100 people! Musk releases the strongest "starship" in history! Go to Mars as early as next year!
4-digit random data
Openwrt增加对 sd card 支持
项目优化个人感悟
JWT简介
企业运维安全就用行云管家堡垒机!
DRF learning notes (I): Data Serialization
DRF learning notes (preparation)
2.2 basic elements of JMeter
Time series ARIMA model
C语言实现字节流与十六进制字符串的相互转换
MapReduce instance (III): data De duplication
Paper_Book