function doIt()
{
var myC1 = new child1Class();
myC1.show();
var myC2 = new child2Class();
myC2.show();
var myC3 = new child3Class();
myC3.show();
var myC4 = new child4Class();
myC4.show();
var myAbstractChild = new abstractChildClass();
myAbstractChild.show();
};
// **********************************************************************************************************
// parentClass ist die "Elternklasse"
function parentClass( a )
{
this.a = ( typeof a == "undefined") ? 1 : a;
this.show = function() {
alert( "Die erste 'Show'-Methode:\na = " + this.a );
};
};
// **********************************************************************************************************
// Die erste Kindklasse überschreibt die "a"-Variable unnd erbt die "show"-Methode:
function child1Class()
{
this.a = 2;
};
child1Class.prototype = new parentClass();
// **********************************************************************************************************
// Die zweite Kindklasse erbt die "a"-Variable und überschreibt die "show"-Methode:
function child2Class()
{
this.show = function() {
alert( " Die zweite 'Show'-Methode:\na = " + this.a );
};
};
child2Class.prototype = new parentClass();
// **********************************************************************************************************
/* Die dritte Kindklasse erbt die "a"-Variable und belegt sie neu,
überschreibt die zweite "show"-Methode und führt eine neue Variable ein:
*/
function child3Class()
{
this.b = 3;
this.show = function() {
alert( " Die dritte 'Show'-Methode:\na = " + this.a + "\nb = " + this.b );
};
};
child3Class.prototype = new parentClass(3);
// **********************************************************************************************************
/* Die vierte Kindklasse überschreibt die "b"-Variable der dritten Kindklasse.
die "show"-Methode stammt aus der dritten Kindklasse
*/
function child4Class()
{
this.b = 4;
};
child4Class.prototype = new child3Class();
// **********************************************************************************************************
// Eine abstrakte Klasse, die auf zwei Variablen einer abgeleiteten Klasse zugreift:
function abstractClass( )
{
this.show = function() {
alert( "Die abstrakte 'Show'-Methode:\n" + this.a + " " + this.b );
};
};
function abstractChildClass()
{
this.a = "Hello";
this.b = "World";
};
abstractChildClass.prototype = new abstractClass();