Created
December 22, 2014 10:23
-
-
Save Inndy/94b338eedc91e0daeed2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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