JavaScript Object

서은서·2023년 3월 11일
0
post-thumbnail

#JavaScript Object

  • Object의 property를 지정할 때는 콤마(,)를 이용함
  • Object의 method를 작성할 때는 함수명 : function(argument){ }; 형식을 따름
const player = {
	name = "eunseo",
    points = 10,
    fat = false,
    level = 1;
    
    sayHello : function(){
    	console.log("Hello");
    };
    
}
  • instance 만드는 방법
var Player = new player();
  • Object에 새로운 property를 수정 혹은 추가
player.name = "eunji";			// name을 수정
player.age = 23;				// age라는 property를 추가
Q. 왜 const로 player 객채를 만들었는데 수정이 가능?
-> player를 바꾸는 것이 아닌 player안의 속성값을 바꿨기 때문!
   const 안의 무언가를 업데이트 하는 것은 가능함!
ex) player = false;				// error 발생
	player.age = 20;			// error 발생하지 않음
profile
내일의 나는 오늘보다 더 나아지기를 :D

0개의 댓글