일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 프로그램
- cocos2d-x
- 자동포스팅
- 자동블로그
- ChatGPT
- vultr
- Javascript
- 챗지피티
- 워드프레스
- 자바스크립트
- Python
- c#
- 파싱
- 자동글쓰기
- vps
- 아두이노 강좌
- 아두이노 초보
- 가상서버
- 파이썬
- 쿠팡파트너스
- 그누보드
- 아두이노 기초강좌
- HTML
- 아두이노
- 웹
- Php공부
- 무료일러스트
- php
- flex
- Ajax
Archives
- Today
- Total
플밍
상속/오버라이딩/부모함수 호출 본문
상속과 오버라이딩 부모함수 호출 방법 예제
#ads_1
<script type="text/javascript>
//***************************
//부모 클래스: Animal
//***************************
var Animal = function(){
this.name = '동물';
}
Animal.prototype.getName = function(){
return this.name;
}
//***************************
//자식 클래스: Animal
//***************************
//생성자 정의
var Dog = function(){
this.name = '개';
}
//Animal을 상속받음
Dog.prototype = new Animal();
//Dog의 생성자 지정
Dog.prototype.contructor = Dog;
//getName 오버라이딩
Dog.prototype.getName = function(){
//부모 함수 호출방법
return '나는 ' + Animal.prototype.getName.call(this) + '입니다';
}
//***************************
//실행
//***************************
var d = new Dog();
alert(d.getName()); //나는 개입니다
</script>
#ads_2
Comments