关于箭头函数的this指向问题

document.onclick = function(){
        // 普通函数的this是在运行的时候才临时绑定的,也就是说,函数不运行,你绝对不可能知道this是谁
        // 下面这个函数如果是自调用,this就是window,比如情况1
        // 如果是被别的对象调用的,this就是调用他的那个对象 比如情况2
        function fn1(){
            console.log(this)
        }
        // 情况1:
        fn1();
        // 情况2:
        button.onclick = fn1();
    
    
    
        // 箭头函数的this在创建的时候就确定好了,
        // 箭头函数的this取决于位于谁的作用域内声明的,
        // 下面这个this在外面function中声名,绑定了外面function的this,这个this绑定了document
        let fn2 = () =>{
            console.log(this)
        }
    
    }
原文地址:https://www.cnblogs.com/wenqiangit/p/9896872.html