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(this)); // <-------------- 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.
@DrAzzy started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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:
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.