생성자 함수
TIL
생성자 함수는 객체를 생성하기 위한 템플릿으로, 비슷한 구조의 객체를 여러 개 만들 때 유용하다. 다음은 동물의 종류와 소리를 인자로 받아 객체를 생성하는 Animal 생성자 함수를 만든 후, makeSound 메서드를 추가한 코드이다.function Animal(type, sound) { this.type = type; this.sound = sound; this.makeSound = function () { return `${this.type}(은/는) ${this.sound}`; };}생성자 함수 내부에서 this 키워드는 생성될 객체를 가리킨다. 생성자 함수의 이름은 일반적으로 대문자로 시작하여 일반 함수와 구분한다. const dog = new Animal("개", "멍멍");con..