Es6的箭头函数

箭头函数是用来简化函数定义语法的:
const fn = () => {
    console.log(123)
 }
 fn();
在箭头函数中 如果函数体中只有一句代码 并且代码的执行结果就是函数的返回值 函数体大括号可以省略
const sum = (n1, n2) => n1 + n2;     
const result = sum(10, 20);
console.log(result)
在箭头函数中 如果形参只有一个 形参外侧的小括号也是可以省略的
 const fn = v => {
     alert(v);
}
 fn(20)
箭头函数不绑定this 箭头函数没有自己的this关键字 如果在箭头函数中使用this this关键字将指向箭头函数定义位置中的this
function fn () {
            console.log(this);
            return () => {
                console.log(this)
            }
        }

        const obj = {name: 'zhangsan'};

        const resFn = fn.call(obj);

        resFn();
原文地址:https://www.cnblogs.com/qingfengyuan/p/12968598.html