JS クラスの勉強
JavaScript クラスの学習
class ClassName { //鋳型、全体の受け皿、ベース
constructor(name,age) { //インスタンス生成のための定義
this.name = name; //プロパティに値を入れる
hits.age = age;
}
method() { //メソッド、関数のようなもの
console.log(`${this.name}`);
}
}
//クラスから生成したオブジェクトは特別にインスタンスと呼ぶ
const ConstantName = new ClassName(arg,arg);
//インスタンス実行
ConstantName.method();
//TIPS
//arg = argument = 引数
メソッド内で同クラスのメソッド呼び出し
//method in method
class hoge {
constructor(name) {
this.name = name;
}
hello() {
console.log("こんにちは");
}
myname() {
this.hello();
console.log(`私の名前は、${this.name}です!`);
}
}
const greet = new hoge("ここあちゃん");
greet.myname();
ディスカッション
コメント一覧
まだ、コメントがありません