且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测对象变量是否已更改?

更新时间:2022-05-10 21:20:20

var fence= {
   set x1(){
      alert('change');
      this.rebuild();
   },
   rebuild: function(){}
}

function Fence(val){
    var value = val;

    this.__defineGetter__("x1", function(){
        return value;
    });

    this.__defineSetter__("x1", function(val){
        alert('change');
        this.rebuild();
    });
    this.rebuild = function(){};
}
var fence = new Fence();