frontend/Java Script

javascript prototype - 상속

Zeronine 2018. 3. 29. 11:10
function Parent(){}
Parent.prototype.Show = function()
{
console.log( "Parent Show" ); // Parent Show 상속해서 사용
}

function A(){}
A.prototype = new Parent();

function B(){}
B.prototype = new Parent();

function C(){}
C.prototype = new Parent();
C.prototype.Show = function()
{
console.log( "C Show" ); // C 에서 Show 함수 캐치
}

var a = new A();
a.Show();

var b = new B();
b.Show();

var c = new C();
c.Show();