開発環境
- 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.587)を解いてみる。
EXERCISE(p.587)
コード(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.errorMessage = 'All systems go.'; Robot.prototype.reportError = function () { print(this.name + ' says ' + this.errorMessage); }; Robot.prototype.spillWater = function () { this.errorMessage = 'I appear to have a short circuit!'; }; robby = new Robot('Robby', 1956, 'Dr.Morbius'); rosie = new Robot('Rosie', 1962, 'George Jetson'); rosie.reportError(); // All systems go. robby.reportError(); // All systems go. robby.spillWater(); rosie.reportError(); // All systems go. robby.reportError(); // I appear to have a short circuit! print(robby.hasOwnProperty('errorMessage')); // true print(rosie.hasOwnProperty('errorMessage')); // false
0 コメント:
コメントを投稿