javascript - How does the WeChat applet monitor and execute a function when certain data are all true?
黄舟
黄舟 2017-05-18 11:03:13
0
2
815


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?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
曾经蜡笔没有小新

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的值’

伊谢尔伦

Reference: /q/10...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template