let carName = "ポルシェ";
let carModel = "911 タルガ";
let carColor = "white";

const startCar = name => {
    console.log(`${name} 出発`);
}

const helloCar = (name, model, color) => {
    const hello = `私の車の名前は${name}で、モデル名は${model}です。色は${color}です。`;
    console.log(hello);
}

const drivingCar = name => {
    console.log(`${name} 運転!`);
}

// 使用例
startCar(carName); // 出力: "ポルシェ 出発"
helloCar(carName, carModel, carColor); // 出力: "私の車の名前はポルシェで、モデル名は911 タルガです。色はwhiteです。"
drivingCar(carName); // 出力: "ポルシェ 運転!"
// Carオブジェクトのコンストラクタ関数
function Car(name, model, color) {
    this.name = name;
    this.model = model;
    this.color = color;
}

// Carオブジェクトのメソッドをプロトタイプに定義
Car.prototype.start = function() {
    console.log(`${this.name} 出発`);
};

Car.prototype.hello = function() {
    const hello = `私の車の名前は${this.name}で、モデル名は${this.model}です。色は${this.color}です。`;
    console.log(hello);
};

Car.prototype.drive = function() {
    console.log(`${this.name} 運転!`);
};

// 使用例
let myCar = new Car("ポルシェ", "911 タルガ", "white");

myCar.start(); // 出力: "ポルシェ 出発"
myCar.hello(); // 出力: "私の車の名前はポルシェで、モデル名は911 タルガです。色はwhiteです。"
myCar.drive(); // 出力: "ポルシェ 運転!"
// 親オブジェクトの宣言
function Animal() {
    this.name = "Animal"; // 親オブジェクト(Animal)が持っている属性です。
}

// 親オブジェクト(Animal)にプロトタイプという方法でメソッドを追加
Animal.prototype.say = function() {
    console.log("I am an animal.");
};

// 子オブジェクトの宣言
function Dog() {
    this.name = "Dog";
}

// プロトタイプという方法で親オブジェクト(Animal)が持っている属性を子オブジェクト(Dog)に継承させる
Dog.prototype = new Animal();

// 子(Dog)オブジェクトで親(Animal)の属性とメソッドを使います。
const myDog = new Dog();
console.log(myDog.name); // 出力: "Dog"
myDog.say(); // 出力: "I am an animal."
function Animal(name) {
    this.name = name;
}

// Animalコンストラクタ関数から生成されたすべてのオブジェクトが継承するプロトタイプオブジェクト
Animal.prototype.speak = function() {
    console.log(`こんにちは、${this.name}です。`);
};

const dog = new Animal("ワンちゃん");
dog.speak(); // 出力: "こんにちは、ワンちゃんです。"
const parent = {
    sayHello: function() {
        console.log("こんにちは!");
    }
};

const child = Object.create(parent);
child.sayHello(); // 出力: "こんにちは!"
class Animal {
    constructor(name) {
        this.name = name;
    }
    
    speak() {
        console.log(`${this.name}が鳴きます。`);
    }
}

class Dog extends Animal { // extendsキーワードでAnimalクラスを継承
    constructor(name, breed) {
        super(name);
        this.breed = breed;
    }

    bark() {
        console.log(`${this.name}が吠えます。`);
    }
}

const myDog = new Dog("ワンワン", "リトリバー");
myDog.speak(); // 出力: "ワンワンが鳴きます。"
myDog.bark();  // 出力: "ワンワンが吠えます。"