I have a few constants defined as globals that I use in my system that I make sure to treat very delicately when evaluating them, having one change because of a programing mistake would be detrimental to the system (as is the use case for most constants constructs).
I noticed rhino supports the const keyword, however if I try to use it in a global definition servoy becomes quite unhappy and sees it as a syntax error. Is the support already in Servoy and I’m perhaps not assigning it correctly?
Of course the ECMAScript implementation of constants leaves a bit to be desired, I would much prefer it to throw an exception in the event something tries to re-assign the value, much like every other language that supports constants that I can think of right now, but we take what we can get I guess.
According to this, https://developer.mozilla.org/en/JavaSc … ents/const Safari and Opera’s engines (I have trouble keeping up with whatever they are named ATM) have some support. But Mozilla has had support since 2000 (JavaScript 1.5), so since we are pretty much married to a Mozilla engine, why not utilize all of its bells and whistles? There’s no reason to attempt cross browser compatibility for a non-browser application as far as i can see…?
As const is a syntactical addition (unlike Continuations for example), external tools might break, like the JSDoc plugin might break (as this one is based in part on Rhino as well, maybe it also supports const, I’m not sure, but you get the idea).
Also, if we would start supporting it now, you’d be relying on it’s behavior, while that might change when the spec gets finalized and implemented.
A correction to what Johan wrote above: support for constants using th ekeyword is in the proposed spec for EcmaScript 6, which, according to their wiki, is due to be finalized this December.
When finalized, proper support still needs to be implemented by JavaScript engines, including the Rhino JavaScript engine used by Servoy, before we could expose it.
Note that the current constants support implemented in the Rhino engine is not compatible with the upcoming standard, hence our decision not to expose it.