javascript - Can a variable be made readonly in Node.js -
i want prevent variable being changed. property of object:
var foo = { bar: 'baz' }; // foo make readonly foo.bar = 'boing'; // should throw exception can done?
you try
object.defineproperty(foo, "bar", { writable: false }); and later assignment either fails silently or, if in strict mode, throws exception (according david flanagan's "javascript : definitive guide" ).
Comments
Post a Comment