js 题

 

 

 

var a = {
    n:1,
    valueOf:function(){
        return this.n++;
    }
};


console.log(
    a == 1 && 
    a == 2 &&
    a == 3
);

 

 

var o = (function(){
    var obj = {
        a:1,
        b:2,
    };
    return {
      get :function(k){
          return obj[k];
      }  
    };
})();
//在不修改上面的代码的情况下, 修改obj
Object.defineProperty(Object.prototype,'abc',{
    get(){
        return this;
    }
});


console.log(o.get('abc'));

 

posted @ 2022-11-02 21:40  AngDH  阅读(19)  评论(0编辑  收藏  举报