当前位置:网站首页>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)) // 6
Extension 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
边栏推荐
- Eureka core ⼼ source code analysis
- Which PHP open source works deserve attention
- Why can't the mobile phone be used and the computer be connected
- QT learning setting executable exe attribute (solving the problem of Chinese attribute garbled)
- Huawei cloud SMS has tested that many mobile phones prompt frequent sending
- 简单好用的缓存库 gcache
- Obsidian basic tutorial
- This 110 year old "longevity" enterprise has been planning for the next century
- Oracle - 基本入门
- Fastjson反序列化随机性失败
猜你喜欢
如何用jmeter做接口测试
oracle -- 表操作
How to use JMeter for interface testing
【EOSIO】EOS/WAX签名错误 is_canonical( c ): signature is not canonical 问题
2022爱分析· IT运维厂商全景报告
How to design a complex business system? From the understanding of domain design, cloud native, micro service, and middle platform
2022年河南省第一届职业技能大赛网络安全项目试题
Canoe: the fifth simulation project: simulation + test
Why is BeanUtils not recommended?
Lecture 14 of the Blue Bridge Cup -- number theory [exercises]
随机推荐
zabbix_server配置文件详解
实战:typora里面如何快捷改变字体颜色(博客分享-完美)-2022.6.25(已解决)
Development trend of China's power carrier communication industry and Research Report on the 14th five year plan 2022 ~ 2028
This 110 year old "longevity" enterprise has been planning for the next century
zabbix_ Server configuration file details
How to open a futures account safely at present? Which futures companies are more reliable?
2022-2028 global industrial TFT LCD industry survey and trend analysis report
What do l and R of earphone mean?
Unity技术手册 - GetKey和GetAxis和GetButton
Multi modal data can also be Mae? Berkeley & Google proposed m3ae to conduct Mae on image and text data! The optimal masking rate can reach 75%, significantly higher than 15% of Bert
Initialization process of gstlibav
Tiger DAO VC产品正式上线,Seektiger生态的有力补充
APP测试要点
2、一个向量乘它的转置,其几何意义是什么?
Unity technical manual - color in life cycle coloroverlifetime-- speed color colorbyspeed
ADB common commands
2022-2028 global vacuum jacket system industry survey and trend analysis report
多模态数据也能进行MAE?伯克利&谷歌提出M3AE,在图像和文本数据上进行MAE!最优掩蔽率可达75%,显著高于BERT的15%...
关闭MongoDB一些服务需要注意的地方(以及开启的相关命令)
As a programmer, how can we learn, grow and progress happily? (personal perception has nothing to do with technology)