In javascript, can I declare properties of an object to be constant?
Here is an example object:
var XU = { Cc: Components.classes }; <
var XU = { Cc: Components.classes };
To define a constant property, you could set the writable attribute to false in the defineProperty method as shown below:
Code snippet:
var XU = {}; Object.defineProperty(XU, 'Cc', { value: 5, writable: false }); XU.Cc = 345; console.log(XU.Cc);
Result:
5 # The value hasn't changed