You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • That's strange... bind should really fix the can't create on undefined error.

    What happens is this.serial.on calls your function, but it calls it as a function, rather than as a method call... so this never gets set to the correct thing.

    this.serial.on( 'data', this.newData.bind(this) ); is a bit like saying:

    x = this;
    this.serial.on( 'data', function(a) {
      x.newData(a);
    });
    

    So it makes sure that newData gets called on the correct object. Hope that makes sense!

About

Avatar for Gordon @Gordon started