開発環境
- 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 13(Extra strength objects: Using Prototypes)、EXERCISE(p.583)を解いてみる。
EXERCISE(p.583)
コード(BBEdit, Emacs)
var Game = function () {
this.level = 0;
},
Robot = function (name, year, owner) {
this.name = name;
this.year = year;
this.owner = owner;
},
game,
robby,
rosie;
Game.prototype.play = function () {
this.level += 1;
print('Welcome to level ' + this.level);
this.unlock();
};
Game.prototype.unlock = function () {
if (this.level === 42) {
Robot.prototype.deployLaser = function () {
print(this.name + ' is blasting you with laser beams.');
};
}
};
game = new Game();
robby = new Robot('Robby', 1956, 'Dr. Morbius');
rosie = new Robot('Rosie', 1962, 'George Jetson');
while (game.level < 42) {
game.play();
}
robby.deployLaser();
rosie.deployLaser();
0 コメント:
コメントを投稿