Object Constructor - 생성자로 객체 만들기

객체 생성자(Object Constructor)는 비슷한 객체를 무수히 만들어낼 수 있다.

cf. 객체 리터럴로 객체를 생성할 수도 있다. var dog = { name: ‘메시’, breed:’푸들’, weight: ‘6kg’}

객체 생성자 만들기

1
2
3
4
5
6
7
function Dog(name, breed, weight) {
//객체 생성자 특징 1. a function, 2.name with Upper Case
this.name = name; //3. 'this' Keywords
this.breed = breed;
this.weight = weight;
//4. return nothing
}

객체 생성자 특징

  1. 객체 생성자는 함수이다.
  2. 생성자 함수명은 일반적으로 대문자로 시작한다.
  3. this 키워드를 사용한다.
  4. 생성자 함수는 아무것도 반환하지 않는다.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×