<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Class</title> </head> <body> <p>Class</p> <script> // -- extends --------------------------------------------------------- // class Parent { // constructor() { // this.parentProperty = "Parent Property"; // } // parentMethod() { // console.log("This is a method from the parent class."); // } // } // class Child extends Parent { // constructor() { // super(); // Parentクラスのコンストラクタを呼び出す // this.childProperty = "Child Property"; // } // childMethod() { // console.log("This is a method from the child class."); // } // } // const childInstance = new Child(); // console.log(childInstance.parentProperty); // "Parent Property" // childInstance.parentMethod(); // "This is a method from the parent class." // -- constructor ------------------------------------------------------- // class Example { // constructor(value) { // this.property = value; // クラスのプロパティに値を設定 // } // } // const instance = new Example("Hello, World!"); // console.log(instance.property); // "Hello, World!" // -- super ------------------------------------------------------- // class Parent { // constructor() { // this.parentProperty = "Parent Property"; // } // } // class Child extends Parent { // constructor() { // super(); // Parentクラスのコンストラクタを呼び出す // this.childProperty = "Child Property"; // } // } // const childInstance = new Child(); // console.log(childInstance.parentProperty); // "Parent Property" // console.log(childInstance.childProperty); // "Child Property" // -- this ------------------------------------------------------- // class Example { // constructor(value) { // this.property = value; // thisは現在のインスタンスを指す // } // showProperty() { // console.log(this.property); // thisを使ってプロパティにアクセス // } // } // const instance = new Example("Hello, World!"); // instance.showProperty(); // "Hello, World!" // -- this ------------------------------------------------------- class Example { constructor(value) { this.property = value; // thisは現在のインスタンスを指す } showProperty() { console.log(this.property); // thisを使ってプロパティにアクセス } } const instance = new Example("Hello, World!"); instance.showProperty(); // "Hello, World!" // -- this ------------------------------------------------------- </script> </body> </html>