Last active
August 29, 2015 14:05
-
-
Save kwatch/ee8717a6a5ba4b6e6be5 to your computer and use it in GitHub Desktop.
数値や文字列をラップしたValueクラスを作るサンプル
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 Length(value, uom) { | |
this.value = value; | |
this.uom = uom || "cm"; | |
} | |
function Square(length, uom) { | |
this.length = new Length(length, uom); | |
} | |
function Colored(figure, r, g, b) { | |
this.__proto__ = figure; | |
this.color = {r: r||0, g: g||0, b: b||0}; | |
} | |
var square = new Square(150, 'cm'); | |
var colored_square = new Colored(square, 127, 0, 0); | |
colored_square.length.value = 1.5; // !!! | |
colored_square.length.uom = 'm'; // !!! | |
colored_square.color.r = 127; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment