Thanks! This looks great - just merged and should go live in the next day or so. I wouldn't worry about the pretokenisation - I'm not actually sure why it'd be giving you any problems, but it might be combination of that and minification.
after I converted the arrow functions into the old ES5 syntax, things are working again
Yeah, this is actually a common thing with arrow functions. They store this from when they are defined (and it overwrites the current this). Yet another fantastic JS design decision that can trip you up!
var outer = {
data : "oops.",
go : function() {
return {
data : "Yay!",
arrow : () => console.log(this.data),
normal : function() { console.log(this.data); }
};
}
};
var a = outer.go();
a.arrow();
//oops.
a.normal();
//Yay!
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! This looks great - just merged and should go live in the next day or so. I wouldn't worry about the pretokenisation - I'm not actually sure why it'd be giving you any problems, but it might be combination of that and minification.
Yeah, this is actually a common thing with arrow functions. They store
this
from when they are defined (and it overwrites the currentthis
). Yet another fantastic JS design decision that can trip you up!(Having said that I did notice a bug in Espruino's arrow function implementation which I'll have to get fixed)