首页 > 其他 > 详细

简单总结es6箭头符号

时间:2018-08-10 18:58:29      阅读:154      评论:0      收藏:0      [点我收藏+]

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;
    });
};

  

简单总结es6箭头符号

原文:https://www.cnblogs.com/huangqiming/p/9456606.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!