jQuery 监控变量是否更新, 变量事件, jquery event on variable changed, jquery listener to var

 

 

直接上代码:

var obj = {
  value: '',
  letMeKnow() {
    console.log(`The variable has changed to ${this.testVar}`);
  },
  get testVar() {
    return this.value;
  },
  set testVar(value) {
    this.value = value;
    this.letMeKnow();
  }
}

console.log(obj.testVar)

obj.testVar = 5;
console.log(obj.testVar)

obj.testVar = 15;
console.log(obj.testVar)

 

 

本文:jQuery 监控变量是否更新, 变量事件, jquery event on variable changed, jquery listener to var

Leave a Reply