開発環境
- OS X Mavericks - Apple(OS)
- Safari, Firefox + Firebug, Google Chrome(Webプラウザ、プラグイン)
- BBEdit - Bare Bones Software, Inc. (GUI) , Emacs (CUI) (Text Editor)
- JavaScript (プログラミング言語)
Head First JavaScript Programming (Eric T. Freeman (著)、 Elisabeth Robson (著)、 O'Reilly Media )のChapter 12(Creating objects: Advanced Object Construction)、EXERCISE(p.531)を解いてみる。
EXERCISE(p.531)
コード(BBEdit, Emacs)
var Coffee = function (roast, ounces) {
this.roast = roast;
this.ounces = ounces;
this.getSize = function () {
switch (this.ounces) {
case 8:
return 'small';
break;
case 12:
return 'medium';
break;
case 16:
return 'large';
break;
default:
return '?';
}
};
this.toString = function () {
return "You've ordered a " + this.getSize() + " " + this.roast +
" coffee.";
};
},
house_blend,
dart_roast;
house_blend = new Coffee('House Blend', 12);
dart_roast = new Coffee('Dart Roast', 16);
print(house_blend.toString());
print(dart_roast.toString());
0 コメント:
コメントを投稿