I've hit a few things recently where it's been a bit annoying to run code on initialisation. For instance say you have two bits of code:
A
function onInit() {
require("my_lcd").connect(...., drawStuff);
}
function drawStuff() {
}
B
function onInit() {
require("my_wifi").connect(...., function() {
requestStuff();
});
}
function requestStuff() {
}
You can't just copy and paste those bits of code - if you do the second onInit will overwrite the first silently and only the second will get executed. You've got to merge the two onInit.
So to me, a good solution would be to have a init event - just like you have for Serial1.on('data', ...);
Any thoughts about what the event should come from? I guess one thought is the global object - so you could do:
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,
I've hit a few things recently where it's been a bit annoying to run code on initialisation. For instance say you have two bits of code:
A
B
You can't just copy and paste those bits of code - if you do the second
onInit
will overwrite the first silently and only the second will get executed. You've got to merge the twoonInit
.So to me, a good solution would be to have a
init
event - just like you have forSerial1.on('data', ...);
Any thoughts about what the event should come from? I guess one thought is the
global
object - so you could do:Or I could put it on the
E
object, like:Any preferences? I guess for me,
E
is edging out, because it's nice and short :)