override 방법

반드시 call(this)를 처럼 해야 됨.

그렇지 않은 경우, Parent의 private메소드를 호출하지 못하게 됨.

MyClassA.prototype.test4 = function() {
alert("MyClassA.prototype.test4" );
MyParent.prototype.test4.call(this);
}

---------------------------------------------------------------------------

예제)

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>무제 문서</title>
<script language="javascript">
function MyParent(nWidth, nHeight)
{
// private 변수 생성.
var width = nWidth;
var height =nHeight;

// 읽기전용 메소드 생성.
this.getWidth = function() {return this.width;}
this.getHeight = function() {return this.height;}
}

// 인스턴스 메소드.
MyParent.prototype.test1 = function()
{
alert("MyParent.prototype.test1 ");
}
// 인스턴스 메소드에서 읽기전용 호출 테스트.
MyParent.prototype.test2 =function ()
{
alert("MyParent.prototype.test2() getWidth = "+this.getWidth());
}

// 인스턴스 메소드에서 읽기전용 호출 테스트.
MyParent.prototype.test3 =function ()
{
alert("MyParent.prototype.test3() getHeight = "+this.getHeight());
}

MyParent.prototype.test4=function()
{
alert("MyParent.prototype.test4");
}

MyParent.prototype.name ="ddan";






function MyClassA(nValue)
{
this.superClass(10,10);
// private 프로퍼티 생성.
this.value = nValue;
}
MyClassA.prototype = new MyParent();
MyClassA.prototype.constructor = MyClassA;
MyClassA.prototype.superClass = MyParent;

// override
MyClassA.prototype.test2 =function()
{
alert("MyClassA.prototype.test2 " );
MyParent.prototype.test2.call(this);
}

// override
MyClassA.prototype.test4 =function()
{
alert("MyClassA.prototype.test4" );
MyParent.prototype.test4.call(this);
}


function on_Load()
{

var objClassA1 = new MyClassA(40);

objClassA1.test1();
// override 한 메소드 호출.
objClassA1.test2();
objClassA1.test3();
// override 한 메소드 호출.
objClassA1.test4();
}


</script>
</head>
<body onLoad="on_Load()">
</body>
</html>

 

'Web > JQuery' 카테고리의 다른 글

checkbox checked 설정  (0) 2014.10.17
Datepicker 대만 번체 zh-TW 번역자료  (0) 2014.07.28
JavaScript Class 상속  (0) 2014.05.21
jQuery.ajax() 사용시 중복호출 방지하는 방법  (0) 2014.05.21
[IE9 짜증남] IE 버전 체크  (0) 2014.05.21

+ Recent posts