首页 > 代码库 > js 对象的深层嵌套函数对对象属性的访问

js 对象的深层嵌套函数对对象属性的访问

var obj = {
    foo: "hi",
    f1: function() {
        function f2(that) {
            console.log(that);
        }
        f2(this.foo);           
    }
        
};
obj.f1();  // hi



Function.prototype.foo = "hello";
Function.prototype.f = function() {
        var that = this;
        setTimeout(function(that){
                console.log(that.foo);
        }, 100, that);
}
Function.prototype.f();  // hello

  

js 对象的深层嵌套函数对对象属性的访问