開発環境
- 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.599)を解いてみる。
EXERCISE(p.599)
コード(BBEdit, Emacs)
var Robot = function (name, year, owner) { this.name = name; this.year = year; this.owner = owner; }, SpaceRobot = function (name, year, owner, home_planet) { this.name = name; this.year = year, this.owner = owner; this.home_planet = home_planet; }, c3po, simon; Robot.prototype.maker = 'ObjectsRUs'; Robot.prototype.speak = function () { print('speaking(Robot prototype)'); }; Robot.prototype.makeCoffee = function () { print('make coffee(Robot prototype)'); }; Robot.prototype.blinkLights = function () { print('blink light(Robot prototype)'); }; SpaceRobot.prototype = new Robot(); SpaceRobot.prototype.speak = function () { print(this.name + ' says Six, If I may venture an opinion...'); }; SpaceRobot.prototype.pilot = function () { print(this.name + ' says Thrusters? Are they important?'); }; c3po = new SpaceRobot('C3PO', 1977, 'Luke Skywalker', 'Tatooine'); c3po.speak(); c3po.pilot(); print(c3po.name + ' wa made by ' + c3po.maker + '.'); simon = new SpaceRobot('Simon', 2009, 'Carla Diana', 'Earth'); simon.makeCoffee(); simon.blinkLights(); simon.speak();
0 コメント:
コメントを投稿