Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- struts2
- oracle
- mybatis
- layout
- 전화걸기
- 클래스
- Java
- paint
- JSP
- 기본
- Menu
- OGNL
- 메서드
- 생성자
- Eclips
- Spring
- AWT
- 안드로이드
- 오버로딩
- HTML
- 에러페이지
- 배열
- 국제화
- 어노테이션
- Android
- JavaScript
- Graphic
- 이클립스
- 메소드
- 예외처리
Archives
- Today
- Total
note
prototype 을 이용한 메서드 생성 본문
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script>
function Student(name,korean,math,english,science){
//속성
this.이름 = name;
this.국어 = korean;
this.수학 = math;
this.영어 = english;
this.과학 = science;
}
Student.prototype.getSum = function (){
return this.국어+this.수학+this.영어+this.과학;
};
Student.prototype.getAverage = function (){
return this.getSum() / 4;
};
Student.prototype.toString = function(){
return this.이름 + '\t' +this.getSum() + '\t'+this.getAverage();
};
//학생 정보 배열을 만듭니다.
var students= [];
students.push(new Student('윤인성', 87, 98, 88, 95));
students.push(new Student('연하진', 92, 98, 96, 98));
students.push(new Student('구지연', 76, 96, 94, 90));
students.push(new Student('나선주', 98, 92, 96, 92));
students.push(new Student('윤아린', 95, 98, 98, 98));
students.push(new Student('윤명월', 64, 88, 92, 92));
students.push(new Student('김미화', 82, 86, 98, 88));
students.push(new Student('김연화', 88, 74, 78, 92));
students.push(new Student('박아현', 97, 92, 88, 95));
students.push(new Student('서준서', 45, 52, 72, 78));
//출력합니다.
var output = '이름\t총점\t평균\n';
for(var i in students){
output += students[i].toString()+'\n';
}
alert(output);
</script>
</head>
<body>
</body>
</html>
자바의 static과 유사하다
'JavaScript > 기본' 카테고리의 다른 글
| 게터와 세터 (0) | 2012.03.14 |
|---|---|
| instanceof 키워드 (0) | 2012.03.14 |
| 생성자 함수를 사용한 객체의 생성과 출력 (0) | 2012.03.13 |
| 학생 성적 출력 (0) | 2012.03.13 |
| 객체의 속성 제거 (0) | 2012.03.13 |