Javascript 5 (ES5) Object properties - creating a constant value

Oscar Brito



To introduce Object Properties in javascript let's create a constant.



var object = {};
Object.defineProperty(
object ,
"constant",
{
value : "NoOneCanChangeMe!"
});


// print NoOneCanChangeMe
console.log(object.constant);

// try to set object.static
object.final= "New Value";

// print NoOneCanChangeMe again
console.log(object.constant);



Nice isn't it?

You can see getter's, setter's, enumeration's  configuations on:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/defineProperty




Visit www.divhide.com for more informations, contacts and news about Web Development.
See other blog posts at blog.divhide.com.



Divhide purpose is to follow the HTML5 movement and contribute with applications which prove the quality of technology.


Feel free to contact divhide.