ES6箭头函数

2018-07-05  本文已影响0人  秋玄语道
<script>
    //ES5
    {
        var events = [1,3,4,5,6,7];
        var odds =events.map(function (v) {
            return v + 1
        })
        console.log(events,odds)
    }

    {
        let events = [1,2,3,4,5];
        let odds =events.map(v => v + 1);
        console.log(events,odds)
    }

    {
        var factory =function () {
            this.a ='a';
            this.b ='b';
            this.c ={
                a : "a+",
                b:function () {
                    return this.a
                }
            }
        }
        console.log(new factory().c.b());
    }
    //ES6
    {
        var factory =function () {
            this.a ='a';
            this.b ='b';
            this.c ={
                a : "a+",
                b: () => {
                    return this.a
                }
            }
        }
        console.log(new factory().c.b());
    }
</script>
上一篇下一篇

猜你喜欢

热点阅读