Thinking through what an implementation of getPrototypeOf() or getClass() (='the function object') could entail, it may not be easily done... Shims or fillins do that by creating an extra instance variable and assign the constructor function - or class (function). Since it is in the constructor itself, it is nothing wrong to 'globally' reference it in there. Taking the same approach for referencing the constructor function - self in itself - and use the (now) available .bind(), simplifies above approach to this:
function EasyVR(...) {
...
this.ser.on('data',EasyVR.prototype.onWatch.bind(this));
...
}
@DrAzzy, renaming onWatch (vs. onTimeout) to onData would go in synch with serial.onData()... ;-)
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.
Thinking through what an implementation of getPrototypeOf() or getClass() (='the function object') could entail, it may not be easily done... Shims or fillins do that by creating an extra instance variable and assign the constructor function - or class (function). Since it is in the constructor itself, it is nothing wrong to 'globally' reference it in there. Taking the same approach for referencing the constructor function - self in itself - and use the (now) available .bind(), simplifies above approach to this:
@DrAzzy, renaming onWatch (vs. onTimeout) to onData would go in synch with serial.onData()... ;-)