学习笔记:ES6之函数扩展(非常重要)
来源:互联网 发布:c语言乘法函数是什么 编辑:程序博客网 时间:2024/06/06 21:39
函数新增特性:
参数默认值
(1)默认值
functiontest1(x,y='world'){
console.log("默认值:",x,y);
}
test1();--undefined world
test1('hello');--hello world
(2)作用域的问题
let x='test';
function test2(x,y=x){
console.log("默认值:",x,y);
}
test2('hello');---hello hello
test2()--undefinedundefined
rest参数:把一系列的参数转换成数值,rest参数之后不能有其他的参数(值转换成数组)
参数的形式: …变量名
rest搭配的变量是一个数组,就可以不再使用arguments对象了
functiontest3(...arg){
for(letv ofarg){
console.log('rest参数',v);
}
}
test3(1,2,3,4,'a');
---
rest参数1
rest参数2
rest参数3
rest参数 4
rest参数 a
扩展运算符:是rest参数的逆运算(将数组转换为用逗号分隔的参数列表)
形式: …
console.log(...[1,2,4]);--124转换成一个个的值
console.log('a',...[1,2,4]);--a 1 2 4
箭头函数(重要)--
函数名 = 函数参数 => 函数返回值
let arrow=v=>v*2;(有参数v)
console.log(arrow(3));--6
let arrow=()=>5;(无参数)
console.log(arrow());--5
this绑定
箭头函数与this进行绑定,视情况而定
尾调用:提升性能
function tail(x){
console.log('tail',x);
}
function fx(x){
return tail(x);
}
fx(123);
- 学习笔记:ES6之函数扩展(非常重要)
- ES6 学习笔记之《函数的扩展》
- es6学习之路(7):函数的扩展
- 学习笔记:ES6之字符串扩展(重要)
- 学习笔记:ES6之数组扩展(重要)
- ES6 学习笔记之《字符串的扩展》
- ES6 学习笔记之《数值的扩展》
- ES6 学习笔记之《数组的扩展》
- 学习笔记:ES6之正则扩展
- 学习笔记:ES6之数值扩展
- 学习笔记:ES6之对象扩展
- ES6学习笔记(三)--字符串扩展
- ES6学习笔记-字符串扩展
- es6之函数的扩展
- ES6学习之路(五) 函数的扩展
- ES6学习笔记二之数组的扩展
- es6 学习笔记(一)箭头函数
- es6函数扩展(六)
- tensorflow session两种运行
- 作为web服务器,nginx和apache对比
- AES加密算法
- 洛谷Oj-求先序排列-String类 + 递归
- Spring bean 中 constructor-arg属性
- 学习笔记:ES6之函数扩展(非常重要)
- left join on and 与 left join on where 的区别
- 【解决方法】点击bootstrap上的下拉菜单无反应
- 功能: 创建文件和删除某个目录下文件 (C#学习日记 2017-09-22)
- Xshell无法连接本地linux虚拟机(多次尝试解决该问题)
- java web最新技术整理
- float 与 absolute
- 文件读写相关函数
- nginx一些技术