search

Home  >  Q&A  >  body text

javascript - How does the WeChat applet monitor and execute a function when certain data are all true?


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?

黄舟黄舟2745 days ago816

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新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的值’
    
    

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-18 11:05:13

    Reference: /q/10...

    reply
    0
  • Cancelreply