開発環境
- 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)、SHARPEN YOUR PENCIL(p.205)を解いてみる。
SHARPEN YOUR PENCIL(p.205)
コード(BBEdit, Emacs)
var eightBall = {
index: 0,
advice: ['yes', 'no', 'maybe', 'not a chance'],
shake: function () {
this.index += 1;
if (this.index >= this.advice.length) {
this.index = 0;
}
},
look: function () {
return this.advice[this.index];
}
};
eightBall.shake();
print(eightBall.look());
eightBall.shake();
print(eightBall.look());
eightBall.shake();
print(eightBall.look());
eightBall.shake();
print(eightBall.look());
eightBall.shake();
print(eightBall.look());
0 コメント:
コメントを投稿