Skip to content

Instantly share code, notes, and snippets.

@kwatch
Last active August 29, 2015 14:05
Show Gist options
  • Save kwatch/ee8717a6a5ba4b6e6be5 to your computer and use it in GitHub Desktop.
Save kwatch/ee8717a6a5ba4b6e6be5 to your computer and use it in GitHub Desktop.
数値や文字列をラップしたValueクラスを作るサンプル
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