javascript 객체 공부

재영·2023년 3월 1일
0
생성자 함수: 객체 생성시 사용하는 함수

function 생성자함수명(변화값){
this.속성값;

}

예시
funcion MINI(color,wheel,roof){
this.brand ="3S"; //고정된값
this.oil=12.3;
this.color=color;
this.wheel=wheel;
this.roof=roof;
this.starting = function(x){
if (x=='on'){
alert(this.color+'인'+this.brand+'가 시동이 켜졌습니다.');
}
}
var csCar= new MINI('blue','16','white');
csCar.starting('on');

Prototype이란 생성자 함수로 생성한 객체들이 properties(속성)과 method(메서드)fmf rh공유하기 위해 사용하는 객체입니다.

-- 같은속성과 메서드이기 때문에 효율화를 위해서 나온것임
동일한 생성자 함수로 생성된 객체들은 내부적으로 [proto]를 가지고 있음

profile
AI 돌리는 강아지

0개의 댓글