Yes - it should be possible. The issue is probably with what happens to the this variable when called from setInterval. It's a standard JS thing...
You could try something like this:
Clock.prototype.start = function() {
var me = this;
setInterval(function() { me.tick(); },1000);
}
This will define a function for each setInterval, but it'll be relatively small.
I'm not sure quite what you're planning, but I wonder how many clock modules a user might have? If it's 1 or 2 it might not matter if the function is duplicated.
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 Martin,
Yes - it should be possible. The issue is probably with what happens to the
this
variable when called fromsetInterval
. It's a standard JS thing...You could try something like this:
This will define a function for each setInterval, but it'll be relatively small.
I'm not sure quite what you're planning, but I wonder how many clock modules a user might have? If it's 1 or 2 it might not matter if the function is duplicated.