Hi. It seems there's a bug in the interpreter that causes this to get reset...
this
It must have crept in recently because that code did work when I wrote it. I've made an issue for it and I'll try and fix it today I hope: https://github.com/espruino/Espruino/issues/233
In the mean time, a simple change of order will help to fix it:
Pin.prototype.startFlashing = function(period) { console.log(this); var pin = this; if (Pin.intervals===undefined) Pin.intervals = []; if (Pin.intervals[pin]) clearInterval(Pin.intervals[pin]); var on = false; Pin.intervals[pin] = setInterval(function() { on = !on; digitalWrite(pin, on); }, period); };
@Gordon 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.
Hi. It seems there's a bug in the interpreter that causes
this
to get reset...It must have crept in recently because that code did work when I wrote it. I've made an issue for it and I'll try and fix it today I hope: https://github.com/espruino/Espruino/issues/233
In the mean time, a simple change of order will help to fix it: