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 | 31 |
Tags
- layout
- 기본
- 메서드
- 클래스
- 국제화
- Java
- struts2
- oracle
- Spring
- 에러페이지
- 전화걸기
- JavaScript
- Android
- Menu
- JSP
- HTML
- AWT
- 메소드
- 배열
- Graphic
- 어노테이션
- mybatis
- paint
- 오버로딩
- 안드로이드
- Eclips
- OGNL
- 예외처리
- 이클립스
- 생성자
Archives
- Today
- Total
note
게터와 세터 본문
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script>
//생성자 함수를 선언합니다
function Rectangle(w,h){
var width= w;
var height = h;
this.getWidth = function () {return width;}
this.getHeight = function () {return height;}
this.setWidth = function (value){
if(value <0){
throw '길이는 음수 일 수 없습니다.';
}else{
width=value;
}
};
this.setHeight=function (value){
if(value < 0){
throw ' 길이는 음수 일 수 없습니다.';
}else{
width = value
}
};
}
Rectangle.prototype.getArea = function (){
return this.getWidth() * this.getHeight();
};
//변수를 선언합니다.
var rectangle = new Rectangle(5,7);
//rectangle.setWidth(-2);
//출력합니다
alert('AREA : '+ rectangle.getArea());
</script>
</head>
<body>
</body>
</html>
34라인 주석 해제시
'JavaScript > 기본' 카테고리의 다른 글
| 기본 자료형에 메서드 추가 (0) | 2012.03.14 |
|---|---|
| 기본 자료형과 객체 (0) | 2012.03.14 |
| instanceof 키워드 (0) | 2012.03.14 |
| prototype 을 이용한 메서드 생성 (0) | 2012.03.14 |
| 생성자 함수를 사용한 객체의 생성과 출력 (0) | 2012.03.13 |