Skip to content

Instantly share code, notes, and snippets.

@zamnuts
Created December 11, 2014 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zamnuts/906885302fb288bd3629 to your computer and use it in GitHub Desktop.
Save zamnuts/906885302fb288bd3629 to your computer and use it in GitHub Desktop.
var C = function C(a,b) {
this.a = a||'';
this.b = b||'';
};
Object.defineProperties(C.prototype,{
a: {
configurable: true,
enumerable: true,
get: function() {
return this._a;
},
set: function(v) {
if ( typeof v === 'undefined' || v === null ) {
v = '';
}
v += '';
this._a = v.toLowerCase();
}
},
_a: {
configurable: false,
enumerable: false,
writable: true,
value: ''
},
b: {
configurable: true,
enumerable: true,
writable: true,
value: ''
}
});
var c = new C('HELLO','WORLD');
console.log('c instance object: ',c);
console.log('c._a enumerable? %s',c._a.propertyIsEnumerable());
console.log('c as stringified JSON: %s',JSON.stringify(c));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment