ES6 箭头函数

箭头函数
  定义函数的方式:()=>{};

  注意:
    1、函数体重只有一句代码,且代码的执行结果就是返回值,可以省略大括号。
    const fn = (a, b) => a + b;
    等价于
    const fun = (a,b) => {
      retuen a+b;
    }

    2、形参只有一个外面的小括号可以省略
    const fn = (a)=> {
      console.log(a);
    }
    等价于
    const fn = a=> {
      console.log(a);
    }

    箭头函数中this问题:箭头函数不绑定this,箭头函数没有自己的this关键字,如果在箭头函数中使用this,this关键字将指向箭头函数定义位置中的this。

原文地址:https://www.cnblogs.com/yanghaoyu0624/p/11496553.html