-
• #2
this is what I use now:
// global vars var release = false; ...... // functions, classes ..... ...... // this will be called on power up, if code was saved onInit(){ ... } if (release) { // save code to flash, to make code permanent setTimeout(save,1E3); } else { // or just start onInit, typical way if you are still developing and testing setTimeout(onInit,1E3); }
Edit: added missing curly bracket open in line 12
-
• #3
...opening curly brace - in line 12 - fell victim to the experience that allows writing code top of your head without testing... (EDIT: obviously fixed now). I like this variable option. Put it as a single line with (could not let go my 'Schnapszahl'):
setTimeout((release)?save:onInit,999);
I use a similar approach for my debugging, logging:
- have a variable each for enabling / disabling it, for example
lon
for log is on - a
log()
that invokesconsole.log(arguments);
to save space - invoking on one line `
if (lon) log(...);
to filter for final load
In (my) emulation I have an overwrite that logs way much more...
It is always a good approach to keep code changes the smallest between dev and release... last but not least also to be able to fall back in case debug is needed without having to change code but just the value of a variable.
- have a variable each for enabling / disabling it, for example
-
• #4
Sun 2020.01.19
ref: code snippets in post #2 and post #3
And we now have a practical working example solution using the Ternary operator
condition ? exprIfTrue : exprIfFalse
explanation and exampleshttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
https://codeburst.io/javascript-the-conditional-ternary-operator-explained-cac7218beeff
Fri 2020.01.17
While I can not take any credit for these examples, having a launching point is needed to save precious moments supporting our Espruino community.
These individuals were cranking out init code solutions two years before I could spell Espruino:
@Ollie post #2
@MaBe post #3
@Gordon post #4
@allObjects post #8 his 0.02 worth
and a must read post #18 two more 0.02 worth
The basic idea:
An excellent read with usage examples, the entire article:
a must read explanation
and another @allObjects gem