ES6 箭头函数使用总结

前言

ES6中添加了箭头函数,可以更方便绑定this作用域了 O.o
至于使用,我觉得一个实例就够了

实例代码

const x = 1;
global.x = 2;
const obj = {
    x: 3,
    fun: function () {
        console.log(this.x); // 3 this => obj
        let fun2 =  () => {
            console.log(this.x); // 3 this => fun => obj
        };
        let fun3 = function () {
            console.log(this.x); // 2 this => global
        };
        fun2();
        fun3();
    }
};

obj.fun();
console.log(this.x); // undefined this => {}

相关文章

原文连接:https://www.cnblogs.com/dupd/p/5951311.htmlES6...
以为Es6,javascript第一次支持了module。ES6的模块化分为导...
视频讲解关于异步处理,ES5的回调使我们陷入地狱,ES6的Prom...
TypeScript什么是TypeScript?TypeScript是由微软开发的一款开...
export class AppComponent { title = 'Tour of heroes...
用 async/await 来处理异步昨天看了一篇vue的教程,作者用as...