IE下的__defineGetter__

火狐针对getter与setter搞了四个好东西,__defineGetter__,__defineSetter__,get与set。IE唯一只能模拟__defineGetter__。

  Object.prototype.__defineGetter__ = function(attributeName,hanlder){
    if(typeof(hanlder)=="string"){
      handler=new Function(hanlder);
    }
    else if(typeof(hanlder)=="function"){
      $owner = this;
      this[attributeName]={
        valueOf:function(){return hanlder.apply($owner, arguments)},
        toString:function(){return hanlder.apply($owner, arguments)}
      };
    }
    else throw new TypeError();
  }

你可能感兴趣的:(getter)