this的使用

全局 this 通常指向全局对象,浏览器中的全局对象就是 window浏览器

console.log(this.document === document); 
console.log(this === window); 
this.a = 91;
console.log(window.a); 

做为对象方法的函数的 this

var o = {
    prop: 37,
    f: function() {
        return this.prop;
    }
};
console.log(o.f()); 
复制代码
相关文章
相关标签/搜索