JavaScript 函数的 this 指向

2021/3/19 22:04:00Chixm12 阅读0 点赞0 评论

this 指向

JAVASCRIPT
function fn(){
            // this 当前执行代码的环境对象
            alert(this)
        }
        // 事件函数下的this 指的就是事件源
        document.onclick = fn;
        // [object Window]
        // js 声明 如果你是在全局环境下声明的 变量 还是 函数 都默认加到window下面
        // window.fn();
        fn();

评论区