-
Right, that won't work—
Object.freeze
only sets the meta object descriptor properties to: [[configurable]]: false, [[writable]]: false. It won't turn a non-object into a const. What you could do is provide a "built-in" keyword whose value istrue
and is essentially a const binding. Special keywords are safe additions, as long as they're not any of the FutureReservedWords: class, enum, extends, super, const, export, import, implements, let, private, public, interface, package, protected, static or yield; additionally, there is precedent in node with bindings likeprocess
, which aren't const, but are special (if you attempt to reassign it, the process itself will crash) -
If the value is actually a floating point number, but you're receiving a string, then you should be able to simply coerce the value to a number and the non-numeric characters will be discarded:
var ph = "8.55\r\n"; +ph === 8.55; // true
Unfortunately, that doesn't seem to work correctly in Espruino. I've filed a bug: https://github.com/espruino/Espruino/issues/268
-
-
I see, I misunderstood.