当前位置:网站首页>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)边栏推荐
- Delete node quickly and efficiently_ modules
- 企业运维安全就用行云管家堡垒机!
- SQL multi table query
- Baidu picture copy picture address
- Nacos
- busybox login: can't execute '/bin/bash': No such file or directory 解决方法
- 无线网络分析有关的安全软件(aircrack-ng)
- Introduction and use of redis
- Servlet基础知识点
- MapReduce instance (III): data De duplication
猜你喜欢

测试新手学习宝典(有思路有想法)

Mapreduce实例(二):求平均值

QT (VI) value and string conversion

flume增量采集mysql数据到kafka

Pychart imports the existing local installation package

scrapy爬虫框架

web测试学习笔记01

MySQL index

Your password does not satisfy the current policy requirements (modify MySQL password policy setting simple password)

DRF learning notes (I): Data Serialization
随机推荐
MapReduce instance (I): wordcount
Pycharm导入已有的Project
The new JMeter function assistant is not under the options menu - in the toolbar
Determine the exact type of data
Text capture picture (Wallpaper of Nezha's demon child coming to the world)
无线网络分析有关的安全软件(aircrack-ng)
DRF use: get request to get data (small example)
借5G东风,联发科欲再战高端市场?
Nacos
Coding skills - Global exception capture & unified return body & Business exception
Common Oracle statements
What is ti's calculation for successively canceling the agency rights of anfuli / Wenye / Shiping?
4位数的随机数据
编码技巧——全局日志开关
Easy to understand, distinguish between ++i and I++
Delete node quickly and efficiently_ modules
Flume incrementally collects MySQL data to Kafka
Openwrt compilation driver module (write code at any position outside the openwrt source code, and compile independently in a modular manner.Ko)
MapReduce instance (III): data De duplication
Nacos