開発環境
- 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.579)を解いてみる。
EXERCISE(p.579)
コード(BBEdit, Emacs)
var Robot = function (name, year, owner) {
this.name = name;
this.year = year;
this.owner = owner;
},
robby,
rosie;
Robot.prototype.maker = 'ObjectsRUs';
Robot.prototype.speak = function () {
print('speaking(prototype)');
};
Robot.prototype.makeCoffee = function () {
print('make coffee(prototype)');
};
Robot.prototype.blinkLights = function () {
print('blink light(prototype)');
};
robby = new Robot('Robby', 1956, 'Dr.Morbius');
rosie = new Robot('Rosie', 1962, 'George Jetson');
robby.onOffSwitch = function () {
print('on/off switch');
};
robby.makeCoffee = function () {
print('make coffee');
};
rosie.cleanHouse = function () {
print('clean house');
};
print(robby.name + ' was made by ' + robby.maker + ' in ' + robby.year +
' and is owned by ' + robby.owner);
robby.makeCoffee();
robby.blinkLights();
print(rosie.name + ' wa made by ' + rosie.maker + ' in ' + rosie.year +
' and is owned by ' + rosie.owner);
rosie.cleanHouse();
0 コメント:
コメントを投稿