You are reading a single comment by @DrAzzy and its replies. Click here to read the full conversation.
  • Thanks, Gordon and allObjects.

    I'll update tonight and try out bind(). That will make the code a lot more readable - can I get rid of the global reference entirely with:

    
    function EasyVR(ser,onCm,onTo) {
      this.ser = ser;
      this.onCommand=onCm;
      this.onTimeout=onTo;
      this.ser.on('data',this.onWatch.bind(thi­s)); // <--------------
      this.vrstate=-1;
      this.stsr='o';
      this.rcvv="";
    } ;
    EasyVR.prototype.onWatch=function(data) {
        console.log(this);
    };
    
    

    I'd really like to get rid of it, since it does defeat the purpose of the class.

    yeah, onData() makes a lot more sense than onWatch(). The variable naming there is very dubious overall, and needs to be cleaned up.

About

Avatar for DrAzzy @DrAzzy started