1.函数能够有默认值 function demo( a = 10,b ){}javascript
2.函数能够使用解构 java
function demo( { a = 0,b = 0 } = {} ){json
}数组
3.函数参数最后能够多一个逗号函数
function demo(a,b,c,){this
}spa
坑:code
1.与for等父子域不一样对象
function(a){token
let a=10;
}
会报错,由于a已经被定义
2.
function move({x, y} = { x: 0, y: 0 })
{ return [x, y]; }
move({x: 3, y: 8});
// [3, 8]
move({x: 3}); // [3, undefined]
move({}); // [undefined, undefined]
move(); // [0, 0]
undefined才
会触发函数参数的默认
简略形式:(参数)=>(return 的数据)
完整形式:
(参数)=>{
语句
return数据
}
做用:解决了this对象,当前this指向最顶层的申明对象
eg:
let json = {
name:"zjj",
demo:function(){
setTimeout(()=>{
alert(this.name);//这里的this再也不是当前的运行时对象,而是最顶层的json
}),200
}
}
坑
1.箭头函数里没有arguments转用...
//错误代码
let show = function(){
alert(arguments);
}
//正确代码
let show = function(...args){
alert(args);
}
2.箭头函数不能做为构造函数
1....
1.散列的数据变成数组
demo(1,2,3,4);
function(a,b,...c){
//a = 1;b = 2 , c = [3,4];
}
2.数组变成散列的数据
let arr1 = [1,2,3];//将arr1复制给另外一个数组
let arr2 = [...arr1];
坑:必须放在最后
幂
2**3=8;