美文网首页
浅谈this

浅谈this

作者: 林小刀2_0 | 来源:发表于2017-07-12 10:00 被阅读0次

    在普通函数中,this指向它的直接调用者;如果找不到直接调用者,则是window:

        var obj = {
            say: function() {
                console.log(this);  //object
                setTimeout(function() {
                    console.log(this);  //windows
                });
            }
        }
    

    匿名函数,定时器中的函数,由于没有默认的宿主对象,所以默认this指向window。

    相关文章

      网友评论

          本文标题:浅谈this

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