js箭头函数 => arrow

//单参数返回后面的表达式
x => x*x;
//相当于
function(x){
    return x*x;
}
//省略了return和{...}



//多参数,返回后面的表达式
(x,y) => x*y;
//相当于
function(x,y){
    return x*y;
}


//无参数,
() =>{ console.log("no_param_function") };
//相当于
function(){
    console.log("no_param_function");
}


//多参数参数,
(x,y) =>{ console.log(x+y) };
//相当于
function(x,y){
    console.log(x+y);
}

箭头函数绑定父上下文,所以this指向同function(){}不同

猜你喜欢

转载自blog.csdn.net/qq_33619285/article/details/70170016