Object literals are a very compact definition and you can use this very naturally. I did use function definition as object and stick my application methods to it, but very rarely. I try to stay more in the confines to not have unexpected side effects. I understand the static aspect and it is helpful to have limited number of globals. Used in Smalltalk (st) the class object as the repository for the instances and related retrieval and storage methods. In st the classes are instances of Class and are also 1st class objects. A lot what I do is still modeled after st. Inheritance is quite different in the various oo languages, but it does not bother me since I use more the composition rather than inheritance. I would not call your approach awkward, but yes it could have some runtime challenges, since yo may not want to inherit certain things of, for example, the function.
Having setTimeout() in the loop for processing of each of the elements is not exactly what I thought about, because you just stack up all the invocations. I was more thinking along the lines of open loop with the loop index being outside.... similar to the approach you use for the led flashing. I made a similar thing a while ago when flashing combination codes w/ green and red led. I constructed a String such as gGgg and RRr and concatenated - queued - for every error code blink to something like that gGggbRRrbRRrr, uppercase for longer and lower case for shorter blink, and b for a break, almost like Morse code.
I do not know what a setTimout() does with 0 [ms]. I use 1 and if I want to stretch it out, I use a higher value, but with 'serialized calls': call the next one at the end of the previous one (as long as there is elements to process in an array or characters in a string).
To have some timing numbers, I was thinking to take the runtime since start and divide by the sum or rxCounts to get a figure how much time could be spent on average to handle an rx event. The other approach for you to figure whether the processor is 'in overdrive'/loaded, you can use setBusyIndicator(pin) or setSleepIndicator(pin).
Furthermore, what I experienced in regard of timing is that minified code just rans faster... especially with long identifiers / symbols that are reduced (most of the time) to single lettes. I also use in general short(er) identifiers, after all the context makes it clear what is going on, a beauty of oo environment (encapsultion).
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.
@ChristianW,
Object literals are a very compact definition and you can use
this
very naturally. I did use function definition as object and stick my application methods to it, but very rarely. I try to stay more in the confines to not have unexpected side effects. I understand the static aspect and it is helpful to have limited number of globals. Used in Smalltalk (st) the class object as the repository for the instances and related retrieval and storage methods. In st the classes are instances of Class and are also 1st class objects. A lot what I do is still modeled after st. Inheritance is quite different in the various oo languages, but it does not bother me since I use more the composition rather than inheritance. I would not call your approach awkward, but yes it could have some runtime challenges, since yo may not want to inherit certain things of, for example, the function.Having setTimeout() in the loop for processing of each of the elements is not exactly what I thought about, because you just stack up all the invocations. I was more thinking along the lines of open loop with the loop index being outside.... similar to the approach you use for the led flashing. I made a similar thing a while ago when flashing combination codes w/ green and red led. I constructed a String such as gGgg and RRr and concatenated - queued - for every error code blink to something like that gGggbRRrbRRrr, uppercase for longer and lower case for shorter blink, and b for a break, almost like Morse code.
I do not know what a setTimout() does with 0 [ms]. I use 1 and if I want to stretch it out, I use a higher value, but with 'serialized calls': call the next one at the end of the previous one (as long as there is elements to process in an array or characters in a string).
To have some timing numbers, I was thinking to take the runtime since start and divide by the sum or rxCounts to get a figure how much time could be spent on average to handle an rx event. The other approach for you to figure whether the processor is 'in overdrive'/loaded, you can use
setBusyIndicator(pin)
orsetSleepIndicator(pin)
.Furthermore, what I experienced in regard of timing is that minified code just rans faster... especially with long identifiers / symbols that are reduced (most of the time) to single lettes. I also use in general short(er) identifiers, after all the context makes it clear what is going on, a beauty of oo environment (encapsultion).