Skip to content

Instantly share code, notes, and snippets.

@Inndy
Created December 22, 2014 10:23
Show Gist options
  • Select an option

  • Save Inndy/94b338eedc91e0daeed2 to your computer and use it in GitHub Desktop.

Select an option

Save Inndy/94b338eedc91e0daeed2 to your computer and use it in GitHub Desktop.
function TestClass (name) {
this.name = name;
this._somevalue = "this._somevalue";
this._read = 0;
}
Object.defineProperty(TestClass.prototype, 'somevalue', {
'get': function () {
console.log(++this._read);
return this._somevalue;
},
'set': function (value) {
console.log(this._somevalue);
console.log(this.name);
this._somevalue = value + 5;
}
});
var obj = new TestClass("This is my name");
obj.somevalue = 8;
console.log(obj.somevalue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment