/* 箭头函数对比 */
function a(a,b){
return a+b;
}
let a1 = (a,b)=>a+b;//如果函数内部只有返回值可以这么写
console.log(a(1,2),a1(1,2));
function b(a,b){
let c = 1;
return a+b+c;
}
let b1 = (a,b) => {
let c = 1;
return a+b+c;
}
console.log(b(1,2),b1(1,2));
let b2 = {
name:"Agwenbi",
age:25
}
//bind
function b3(){
console.log(this.name);
}
b3();//此时的函数内部的this指向window
b3.bind(b2)();//此时的函数内部的this指向b2
//apply
function b4(a=0,b=0){
console.log(a,b,this);
}
b4.apply(b2,[1,2]);//参数要用数组包裹,this指向b2
b4.apply(b2);//没有参数可以不写,this指向b2
//call
function b5(a=0,b=0){
console.log(a,b,this);
}
let b6 = [2,3];
b5.call(b2,1,2);//与apply的不同就在于参数传递的形式
b5.call(b2,...b6);
/* 箭头函数对比 */
/* 参数的默认值 */
let c = (a = 0,b = 0) => a + b;
console.log(c(),c(1,2));
let c1 = (a = 0,b = a)=> a + b;
console.log(c1(),c1(1),c1(1,2));
/* 参数的默认值 */
/* 扩展运算符 */
let d = [1,2,3,4,5,6];
let d1 = d;//此方法是直接将地址复制,后续操作d1会改变d
let d2 = [...d];//反之
console.log(d == d1,d == d2,d1 == d2);
let d3 = (a,b,c,d,e,f)=> a + b + c + d + e + f;
console.log(d3(...d));
/* 扩展运算符 */
/* rest运算符 */
let e = (a,...args)=>{
console.log(a,args);
}
e(1,2,3,4,5);
/* rest运算符 */