图解javascript的this指向

图解javascript的this指向

作者: HerryLo

本文永久有效链接: https://github.com/AttemptWeb......

以下就只有两张图,请放心食用!!

#简版this指向

#升级版this指向

#解释:

这里的上下文对象如下:

function fn() {console.log('this指向:', this);}

let Obj = {
    fn: fn
}

window.fn();    // 上下文对象调用, 等价于直接调用 fn()
Obj.fn();       // 上下文对象调用

#参考:

MDN: 箭头函数表达式

MDN: 函数的this

posted @ 2019-09-12 17:01  herryLo  阅读(183)  评论(0编辑  收藏  举报