How can you make a variable/Object read only in Javascript? [duplicate]

In the current widely available implementation, ECMAScript 3 there is no support for real immutability.

UPDATE: Nowadays, the ECMAScript 5 standard is widely supported. It adds the Object.seal and Object.freeze methods.

The Object.seal method will prevent property additions, still allowing the user to write to or edit the existing properties.

The Object.freeze method will completely lock an object. Objects will stay exactly as they were when you freeze them. Once an object is frozen, it cannot be unfrozen.

More info:

  • ECMAScript 5 Objects and Properties

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)