简单总结es6箭头符号

1、es6箭头符号的几种写法

(1)没有参数

()=>1*1

(2)一个参数

x=>x*x

(3)两个参数以及多个参数

(x,y,z)=>x*y*z

2、箭头符号不会绑定this、arguments、super、new.target

(1)arguments

function foo() {
    setTimeout( () => {
        console.log("args:", arguments);
    },100);
}

foo( 2, 4, 6, 8 );

(2)this

function Prefixer(prefix) {
    this.prefix = prefix;
}
Prefixer.prototype.prefixArray = function (arr) {
    return arr.map((x) => {
        return this.prefix + x;
    });
};

  

猜你喜欢

转载自www.cnblogs.com/huangqiming/p/9456606.html