String append with += is definitely pretty efficient - as the string will be appended rather than copied to a new string each time.
That's a great use of String.fromCharCode.apply in fromByteArray - however there is actually E.toString which allows you to do that in one big chunk (because there didn't seem to be a nice way in JS itself).
@Kartman yes, the code is a bit cryptic! Unfortunately there's nothing built-in. Node.js has Buffer.toString(encoding) which would have been perfect, but we don't have Buffer in Espruino - just DataView which is depressingly similar, but without a .toString(encoding) option
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.
String append with
+=
is definitely pretty efficient - as the string will be appended rather than copied to a new string each time.That's a great use of
String.fromCharCode.apply
infromByteArray
- however there is actuallyE.toString
which allows you to do that in one big chunk (because there didn't seem to be a nice way in JS itself).@Kartman yes, the code is a bit cryptic! Unfortunately there's nothing built-in. Node.js has
Buffer.toString(encoding)
which would have been perfect, but we don't haveBuffer
in Espruino - justDataView
which is depressingly similar, but without a.toString(encoding)
option