当前位置:网站首页>ES6 -- formal parameter setting initial value, extension operator, iterator, and generating function
ES6 -- formal parameter setting initial value, extension operator, iterator, and generating function
2022-06-25 23:03:00 【Climbing procedural ape】
Formal parameter setting initial value
characteristic
(1) Be similar to python Set the initial value of the formal parameter of
(2) Parameters with default values , All in the back
function add(a, b, c = 10) {
return a + b + c;
}
console.log(add(1, 2)) // 13
let options = [1, 2, 3, 4, 5]
console.log(add(...options)) // 6Extension operator
characteristic :
(1) Convert the array to a comma separated sequence of parameters
const TF_BOYS = [' Jackson Yi ', ' hanah ', ' Juen-Kai Wang ']
function chunwan() {
console.log(arguments) // ' Jackson Yi ', ' hanah ', ' Juen-Kai Wang '
}
chunwan(...TF_BOYS)
// Array merge
const KUAI_ZI = [' Wang Taili ', ' Xiao Yang ']
const FENG_HUANG = [' Zeng Yi ', ' Linghua ']
console.log(KUAI_ZI.concat(FENG_HUANG))
console.log([...KUAI_ZI, ...FENG_HUANG]) // The performance is much higher than concat
// Copy of , If there is a reference type , It's a light copy
let kuai_zi1 = [...KUAI_ZI](2) Object extension operator
Object extension operations can be used for object merging , Regenerate the rest directly into an object, etc , Expanding is similar to a Map
const CONFIG = {
host: '127.0.0.1',
port: '3306',
username: 'root',
password: 'root'
}
function connect({host, port, ...user}) {
console.log(host)
console.log(port)
console.log(user)
}
connect(CONFIG)
const CONFIG1 = {
type: 'oracle'
}
const CONFIG2 = {
cmd: 'sqlplus'
}
console.log({...CONFIG, ...CONFIG1, ...CONFIG2})iterator
characteristic
(1)Array、Arguments、Set、Map、String、TypeArray、NodeList Deployed Iterator Interface ( An attribute in an object ) Can use iterators to traverse
(2) You can customize [Symbol.iterator] Method , Define the elements in the traversal object , I feel a little silly
Silicon Valley Web front end ES6 course , cover ES6-ES11_ Bili, Bili _bilibili
const XIYOU = [' Tang's monk ', ' The Monkey King ', ' Pig eight quit ', ' Monk sha ']
for (let item of XIYOU) {
console.log(item)
}
for (let item of ' I am the king of ox horn '){
console.log(item)
}
Generator function
characteristic :
(1) Asynchronous programming , Pure callback functions
function * generator() {
console.log(111)
yield ' Never had ears ' // yield Code segmentation , It can be used for segmented debugging ,next Just pass in the arguments , Asynchronous programming parameter passing
console.log(222)
yield ' Never had a tail '
console.log(333)
yield ' It's strange. '
console.log(444)
}
let iterator = generator();
// iterator.next() // 111
// iterator.next() // 222
// iterator.next() // 333
// iterator.next() // 444
for (let item of iterator){
console.log(item)
}Asynchronous programming
JavaScript It's single threaded , Using asynchronous mode can avoid thread switching , Save resources , But the native writing is difficult to read and view
// Traditional callback functions
setTimeout(() => {
console.log(' Callback programming ')
setTimeout(()=>{
console.log(' Wait first 2s Besides, ')
},2000)
}, 2000)
console.log(' You will see me immediately ')
Promise Solution -- Study alone
边栏推荐
- Cvpr2022 tutorial | machine learning remote sensing processing: agriculture and food security, University of Maryland
- 面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?
- Nacos source code analysis 01 code structure
- Basic concepts of processor scheduling
- Three layer architecture + routing experiment
- Chapter 3 use of requests Library
- The wisdom of questioning? How to ask questions?
- Development trend of China's power carrier communication industry and Research Report on the 14th five year plan 2022 ~ 2028
- 2022-2028 global RBI platform industry research and trend analysis report
- 2022 love analysis · panoramic report of it operation and maintenance manufacturers
猜你喜欢
[email protected]@COLLATION_CONNECTION */"/>.sql数据库导入错误:/*!40101 SET @[email protected]@COLLATION_CONNECTION */
![Lecture 14 of the Blue Bridge Cup -- number theory [exercises]](/img/96/0971909c8bf25820c2d4f520bb83fb.jpg)
Lecture 14 of the Blue Bridge Cup -- number theory [exercises]

Fastjson deserialization randomness failed

Use of local stack in flask

2022年河南省第一届职业技能大赛网络安全项目试题

2022-2028 global extrusion coating and lamination production line industry research and trend analysis report

2022-2028 global TFT LCD touch screen industry research and trend analysis report

2022-2028 global vacuum jacket system industry survey and trend analysis report

2022 love analysis · panoramic report of it operation and maintenance manufacturers

Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant
随机推荐
Fastjson反序列化随机性失败
实战:typora里面如何快捷改变字体颜色(博客分享-完美)-2022.6.25(已解决)
ORACLE - 数据查询
How to open a futures account safely at present? Which futures companies are more reliable?
Unity technical manual - life cycle rotation rotationoverlifetime- speed rotation rotationbyspeed- and external forces
2022-2028 global carbon fiber unidirectional tape industry research and trend analysis report
作为一个程序员我们如何快乐的学习成长进步呢?(个人感悟和技术无关)
GStreamer initialization and plugin registry procedures
What are the channels for Internet advertising to gain customers?
2022-2028 global cloud based remote browser isolation industry research and trend analysis report
Unity技术手册 - 生命周期内颜色ColorOverLifetime--速度颜色ColorBySpeed
Raspberry PI (bullseye) replacement method of Alibaba cloud source
Analysis report on market business model and development direction of China mobile operation industry from 2022 to 2028
你好,请问老师,在支付宝基金开户真的安全吗?
Relinearization in homomorphic encryption (ckks)
Development trend of China's power carrier communication industry and Research Report on the 14th five year plan 2022 ~ 2028
等价类,边界值,场景法的使用方法和运用场景
MySQL数据库索引
Analysis report on market demand situation and investment direction of China's optical transmission equipment industry from 2022 to 2028
Hello, teacher, is it really safe to open an account in Alipay fund?