목차

1️⃣ 객체와 배열

2️⃣ this

3️⃣ new 연산자와 생성자 함수(Constructor Function)

4️⃣ 원형 (Prototype)

5️⃣ class

1️⃣ 객체와 배열

const myMath = {
	PI : Math.PI,  // name(key)와 value로 변수에 값을 추가
	random : function () {
		return Math.random();
	}, // name의 value로 함수를 넣을 수도 있다. 이것을 '메소드'라고 말한다.
	floor: function(int) {
		return Math.floor(int);
	}
}

console.log("myMath.PI", myMath.PI);
console.log("myMath.random()", myMath.random());
console.log("myMath.floor(3,9)", myMath.floor(3.9));

이처럼 객체를 이용하면 서로 연관된 변수나 함수들을 객체라는 존재에 하나로 그룹핑하여 관리할 수 있다.

2️⃣ this

const kim = {
    name:'kim',
    first:10,
    second:20,
    sum:function(){
        return this.first+this.second;
    }
}

console.log("kim.sum(kim.first, kim.second)", kim.sum());