Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> Object-oriented Inheritance instance </title>
<Script type = "text/javascript">
Window. onload = function (){
Function parent (age, name ){
This. age = age;
This. name = name;
}
Parent. prototype. show = function (){
Alert ('parent method ');
}
Function child (age, name, job ){
Parent. apply (this, arguments );
This. job = job;
}
(Function (){
For (var I in parent. prototype ){
Child. prototype [I] = parent. prototype [I]
}
})();
Var B = new parent (14, 'knight pass ');
Var a = new child (15, 'Wolf Xia ', 'knight ');
A. show ();
}
</Script>
</Head>
<Body>
<H1> Object-oriented Inheritance instance <P> I often see interview questions about inheritance. a. How to inherit B? I decided to write about it. In fact, inheritance is to inherit the attributes and methods of the parent level. </p>
</Body>
</Html>