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

  

posted @ 2017-04-29 03:15  ax=null  阅读(3920)  评论(0编辑  收藏  举报