For example, these values will change, and the function inside needs to be triggered when these values are true. So where is this code written? Can these values be monitored in real time? I previously found that the function inside was not executed because I wrote this code in onload. Now it seems that it is not working. Does anyone have any good ideas?
曾经蜡笔没有小新2017-05-18 11:05:13
You can monitor the corresponding events through the getter and setter of JS Object
var obj = {
val: 100,
get getval() {
console.log('访问了getVal的值');
return this.val;
},
set setval(x) {
console.log('设置getVal的值');
this.val = x;
}
}
// 在访问 obj.getval时,将会看到 ‘访问了getVal的值’
// 在设置 obj.setval=1000时,会看到 ‘设置getVal的值’