Created
December 11, 2011 16:11
-
-
Save emonkak/1461320 to your computer and use it in GitHub Desktop.
inherit.js
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 Klass(x) | |
| { | |
| this.member = { | |
| x: x, | |
| }; | |
| } | |
| Klass.prototype = { | |
| get x() { | |
| return this.member.x; | |
| }, | |
| set x(x) { | |
| this.member.x = x; | |
| }, | |
| }; | |
| function KlassDouble(x) | |
| { | |
| Klass.call(this, x); | |
| } | |
| KlassDouble.prototype = { | |
| __proto__: Klass.prototype, | |
| get y() { | |
| return this.x * 2; | |
| }, | |
| set y(y) { | |
| this.x = y * 2; | |
| }, | |
| }; | |
| var klass = new KlassDouble(1); | |
| console.log(klass.x); // 1 | |
| console.log(klass.y); // 2 | |
| klass.x = 10; | |
| console.log(klass.x); // 10 | |
| console.log(klass.y); // 20 | |
| klass.y = 10; | |
| console.log(klass.x); // 20 | |
| console.log(klass.y); // 40 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment