PDA

View Full Version : Const question.



???
08-03-2007, 05:16 PM
If you make an constant object, can one of its sub variables (or whatever they are) also be a constant?


const Obj = new Object ();
Obj.subThing = new Array ();
Is there any way to make Obj.subThing a constant?

jscheuer1
08-03-2007, 05:26 PM
No, it is a property of the object. It cannot be made to be a variable either. If your problem is that you don't want the value of it to change, then you just need to determine a way to establish its value that is not itself an object and/or subject to being updated dynamically by the rest of your code. Or, depending upon the code, you may be able to make sure it doesn't get updated.

Also, constants are not widely supported in javascript yet, their values (contrary to the supposed standard) can change.