개발개발/자바스크립트
프로토타입
공돌공돌
2012. 8. 27. 14:00
<script type="text/javascript">
function Student(name, korean, math, english, science) {
this.이름 = name;
this.국어 = korean;
this.수학 = math;
this.영어 = english;
this.과학 = science;
}
Student.prototype.getSum = function () {};
Student.prototype.getAverage = function () {};
Student.prototype.toString = function () {};
</script>
프로토타입은 생성자 함수를 사용해 생성된 객체가 공통으로 가지는 공간으로
각각의 객체가 가지고 있는 메서드를 한 공간으로 옮긴다
프로토타입을 사용하면 이미 있는 객체에 추가로 메소드를 제공할 수 있다