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

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

php - HTTP_REFERER woes: How can I allow access to a specific page, only when a visitor has visited another specific page beforehand? -