2014年9月26日金曜日

開発環境

Head First JavaScript Programming (Eric T. Freeman (著)、 Elisabeth Robson (著)、 O'Reilly Media )のChapter 12(Creating objects: Advanced Object Construction)、EXERCISE(p.537)を解いてみる。

EXERCISE(p.537)

コード(BBEdit, Emacs)

var Car = function (make, model, year, color, passengers, convertible, mileage) {
        this.make = make;
        this.model = model;
        this.year = year;
        this.color = color;
        this.passengers = passengers;
        this.convertible = convertible;
        this.mileage = mileage;
        this.start = function () {
            this.started = true;
        };
        this.stop = function () {
            this.started = false;
        };
        this.drive = function () {
            if (this.started) {
                print(this.make + ' ' + this.model + ' goes zoom zoom!');
            } else {
                print('Start the engine first.');
            }
        };
    },
    chevy;

chevy = new Car('Chevy', 'Bel Air', 1957, 'red', 2, false, 1021);
chevy.drive();
chevy.start();
chevy.drive();
chevy.stop();
chevy.drive();










						

0 コメント:

コメントを投稿