<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>
<script>
function person (name, sex)
{
This.name=name;
This.sex=sex;
}
Person.prototype.showname=function ()
{
alert (this.name);
};
Person.prototype.showsex=function ()
{
alert (this.sex);
};
//-------------------------------------
function Worker (name, sex, job)
{
This->new out of the worker object
The constructor pretends to call the parent's constructor--in order to inherit the property
Person.call (this, name, sex);
This.job=job;
}
Prototype chain inherits the parent's method through the prototype.
Worker.prototype=person.prototype;
for (var i in Person.prototype)
{
Worker.prototype[i]=person.prototype[i];
}
Worker.prototype.showjob=function ()
{
alert (this.job);
};
var op=new person (' zgz ', ' Male ');
var ow=new Worker (' zgz ', ' Male ', ' handyman ');
Op.showname ();
Op.showsex ();
Ow.showname ();
Ow.showsex ();
Ow.showjob ();
</script>
<body>
</body>
Object-Oriented Inheritance ~