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 is true 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 like process, which aren't const, but are special (if you attempt to reassign it, the process itself will crash)
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.
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)