/ Published in: JavaScript
Expand |
Embed | Plain Text
var myObject = {}; //wrapping Object.defineProperty in a function like this feels very hacky (function() { var myProp = 'myDefault'; Object.defineProperty( myObject, 'myProp', { enumerable: false, configurable: true, get: function() { return myProp; }, set: function( v ) { myProp = v+' is mo beta'; } }); })(); alert( myObject.myProp ); myObject.myProp = 'myValue'; alert( myObject.myProp ); /* COULDN'T IT HAVE JUST BEEN.... Object.defineProperty( myObject, 'myProp', { writable: false, enumerable: false, configurable: true, value: 'myDefault', get: function() { return myProp; }, set: function( v ) { myProp = v+' is mo beta'; } }); */
Comments
Subscribe to comments
You need to login to post a comment.

I meant to replace 'myProp' in the getter/setter functions with 'value';
/* COULDN'T IT HAVE JUST BEEN....
*/