/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var myObject = {}; Object.defineProperty( myObject, '_myProp', { value: 'myDefault', writable: false, enumberable: false, configurable: true }); Object.defineProperty( myObject, 'myProp', { enumberable: true, configurable: true, set: function( v ) { Object.defineProperty( this, '_myProp', { writable:true } ); this._myProp = v; Object.defineProperty( this, '_myProp', { writable:false } ); }, get: function() { return this._myProp; } }); alert( myObject.myProp ); myObject.myProp = 'myValue'; alert( myObject.myProp ); myObject._myProp = 'teehee, not writable'; alert( myObject._myProp );