Use JavaScript to simulate objects and create a person class. The class must have the name and age attributes. Then, use inheritance to implement the programmer class. The class must have the name, age, gender, and language attributes.
The following is the implementationCode(This inheritance uses the prototype chain implementation ):
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd" > < Html Xmlns = "Http://www.w3.org/1999/xhtml" > < Head > < Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = UTF-8" /> < Title > New Web project </ Title > < Style Type = "Text/CSS" > Span { Color : #66a300 ; Font-family : "Arial black" ; } </ Style > </ Head > < Body > < Div ID = "Main" > < Span > Hello! </ Span > </ Div > < Script Type = "Text/JavaScript" > Function Person (name, age ){ This . Name = Name; This . Age = Age ;} Function Programmer (name, age, sex, language) {person. Call ( This , Name, age); // inherited class Constructor This . Sex = Sex; This . Language = Language ;} // Set prototype chain Programmer. Prototype = New Person (); programmer. Prototype. Constructor = Programmer; programmer. Prototype. getname = Function (){ Return This . Name ;} VaR Smirk = New Programmer ( " ZY " , 21 , " F " , " English " ); Alert (smirk. getname ()); </ Script > </ Body > </ Html >