// Define a class
Function testclass (name)
{
// Define an attribute and set the default value
This. Name = Name | "jxh ";
// Define an Object Property
This. internalclass = new internalclass (this. Name );
// Define a method
This. getformatname = function ()
{
VaR fname = This. internalclass. formatname ();
Return fname;
}
}
// Internal class
Function internalclass (name)
{
This. internalname = Name;
}
// Inherit the subclass of testclass
Function subjectclass (name)
{
This. base = testclass;
This. Base (name );
}
When inheriting, you are concerned about whether the parent class and the subclass operate on the same object when the parent class has referenced objects. <script language = "JavaScript">
Function click_event ()
{
VaR testclass = new testclass (); // declare the parent class
VaR subjectclass = new subjectclass ("jxhwei"); // declare a subclass
VaR name = "parent class:" + testclass. internalclass. internalname; // call the object attribute of the parent class
Name + = "\ r \ n subclass :";
Name + = subjectclass. internalclass. internalname; // call the object attribute of the subclass.
Alert (name );
}
</SCRIPT>
Running result, OK