Problem Description:
How JavaScript implements classes?
How to achieve inheritance?
Solution:
http://www.w3.org/tr/xhtml1/dtd/xhtml1-transition.dtd ">>
http://www.w3.org/1999/xhtml>>
Function human ()
{
? THIS._CLASSNAME = "human";
? this.name = "";
? THIS.AGE = new number () ;?
}
Var_p = human.prototype;
_P.SAY = function () {alert ("i 'm" this.name);
Function EMPLOYEE ()
{
? THIS._CLASSNAME = "EMPLOYEE";
? this.company = "";
? this.professional = "";
}
_P = Employee.Prototype = new human ();
_P.show = function () {alert (this.name "/ n" this.age "/ n" this.professional "/ n" this.company);
VAR JJS = New Employee ();
JJS.NAME = "jiangjs";
JJS.AGE = 25;
Jjs.company = "Huawei Software";
Jjs.professional = "Web Developer";
Jjs.say ();
JJS.SHOW ();
Alert (JJS._CLASSNAME);
script>
Detailed explanation:
It can be seen from the code that the Employee class inherits the properties and methods of the Human class.
Prototype attribute Returns a reference to the object type prototype
Provide a set of basic functions of the class of the object with the prototype attribute. The new instance of the object "Inherit" gives the object of the object prototype.
All JScript internal objects have a read-only Prototype property.
The Prototype property is the property in the JavaScript ECMA standard, so the above code can run in IE, Mozzila.