I do not have much experience with JavaScript (have quite a bit with Java).
It is weird issue from my perspective. If I assign an object's method call to event, it runs in empty object instance. All fields are empty. But if I wrap object's method into a function, and put into event, it runs ok. Is it normal?
Example:
const O = {
A:"", B:0,
M : function(){
this.A = this.A + "*";
this.B = this.B + 1;
print(this.A," - ", this.B);
}
};
function F(){
O.M();
}
// uncomment one or another call and run
//setInterval(O.M, 1000); // method M runs in empty object instance
//setInterval(F, 1000); // method M runs in populated object instance
Output of direct method assignment
undefined* - NaN
undefined** - NaN
undefined*** - NaN
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.
I do not have much experience with JavaScript (have quite a bit with Java).
It is weird issue from my perspective. If I assign an object's method call to event, it runs in empty object instance. All fields are empty. But if I wrap object's method into a function, and put into event, it runs ok. Is it normal?
Example:
Output of direct method assignment
Output of wrapped method assignment