美文网首页
ES6箭头函数

ES6箭头函数

作者: 秋玄语道 | 来源:发表于2018-07-05 20:27 被阅读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>
    

    相关文章

      网友评论

          本文标题:ES6箭头函数

          本文链接:https://www.haomeiwen.com/subject/ghkmuftx.html