コンストラクタ
3831 ワード
コンストラクタ
必要な材料を入れてつけたようなフナの皿
構文
function User(name, age){ // 첫 글자는 대문자로
this.name = name;
this.age = age;
}
let user1 = new User("Mike", 30);
let user2 = new User("Jan", 17);
let user3 = new User("Tom", 20);
function User(name, age){ // 첫 글자는 대문자로
this.name = name;
this.age = age;
}
let user1 = new User("Mike", 30);
let user2 = new User("Jan", 17);
let user3 = new User("Tom", 20);
new
演算子呼び出しを使用使用理由
動作原理
function User(name, age){
// this = {}; -> 빈 객체가 임시적으로 만들어짐
// 새로운 프로퍼티을 this에 추가
this.name = name;
this.age = age;
// return this;
}
new 함수명();
new関数名を実行する場合()
this={}空のオブジェクトを作成します.
ここにPropertyを追加します.
最後にthisに戻ります.
リファレンス
Reference
この問題について(コンストラクタ), 我々は、より多くの情報をここで見つけました https://velog.io/@hoho_0815/생성자-함수テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol