開発環境
- 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 5(Understanding Objects: A trip to Objectville)、EXERCISE(p.207)を解いてみる。
EXERCISE(p.207)
コード(BBEdit, Emacs)
var cadi = {
make: "GM",
model: "Cadillac",
year: 1955,
color: "tan",
passengers: 5,
convertible: false,
mileage: 12892,
started: false,
start: function () {
this.started = true;
},
stop: function () {
this.started = false;
},
drive: function () {
if (this.started) {
print(this.make + ' ' + this.model + ' goes zoom zoom!');
} else {
print('You need to start the engine first.');
}
}
},
chevy = {
make: "Chevy",
model: "Bel Air",
year: 1957,
color: "red",
passengers: 2,
convertible: false,
mileage: 1021,
started: false,
start: function () {
this.started = true;
},
stop: function () {
this.started = false;
},
drive: function () {
if (this.started) {
print(this.make + ' ' + this.model + ' goes zoom zoom!');
} else {
print('You need to start the engine first.');
}
}
},
taxi = {
make: "Webville Motors",
model: "Taxi",
year: 1955,
color: "yellow",
passengers: 4,
convertible: false,
mileage: 281341,
started: false,
start: function () {
this.started = true;
},
stop: function () {
this.started = false;
},
drive: function () {
if (this.started) {
print(this.make + ' ' + this.model + ' goes zoom zoom!');
} else {
print('You need to start the engine first.');
}
}
};
cadi.start();
cadi.drive();
cadi.stop();
chevy.start();
chevy.drive();
chevy.stop();
taxi.start();
taxi.drive();
taxi.stop();
0 コメント:
コメントを投稿