객체지향 JavaScript

마데슾 : My Dev Space·2019년 9월 21일
0

[CODESTATES]PRE

목록 보기
3/19

속성 = 현재상태
메소드 = 액션

let arr = [1,2,3,4,5]
let arr1 = new Array(1,2,3,4,5); // [1, 2, 3, 4, 5]
// 우리가 배열을 정의하는 것은 Array의 인스턴스를 만들어내는 것과 동일함
function Student(name, score, hobby) {
  this.name = name;
  this.score = score;
  this.hobby = hobby;
}
Student.prototype.study = function() {
	console.log(this.name + '가 JS를 공부하고있습니다')
}
let student1 = new Student('heaeun', 100, 'lol');

student1.name // "heaeun"
student1.study() // heaeun가 JS를 공부하고있습니다
  • mdn 메소드 설명에 prototype이라고 붙어있는 이유?
    : push 구현이 원형 객체에 정의되어 있기 때문입니다.

< 용어 설명 >
1. prototype : 모델의 청사진을 만들 때 쓰는 원형 객체(original form)입니다.
2. constructor : 인스턴스가 초기화될 때 실행하는 생성자 함수
3. this

  • 함수가 실행될 때, scope마다 생성되는 고유한 실행 context (execution context)
  • new 키워드로 인스턴스를 생성했을 때에는, 해당 인스턴스가 바로 this의 값이 됨
profile
👩🏻‍💻 🚀

0개의 댓글