// Define a class
Function testclass (name)
{
// Total number of initialization + 1
Testclass. Prototype. Count ++ ;
// Define an attribute and set the default value
This . Name = Name | " Jxh " ;
// Define a static class Property
Testclass. Prototype. Current. internalname = This . Name;
// Define an Object Property
This . Internalclass = New Internalclass ( This . Name );
// Define a method
This . Getformatname = Function ()
{
VaR fname= This. Internalclass. formatname ();
ReturnFname;
}
}
// Defines a static attribute for the testclass class.
Testclass. Prototype. Count = 0 ;
// Defines a static class attribute for the testclass class.
Testclass. Prototype. Current = New Internalclass ( " No instance " );
// Internal class
Function internalclass (name)
{
This. Internalname=Name;
}
For access to static attributes, except for the [class name. prototype. in addition to the access method of attribute name, the [Object Name. attribute name] can be accessed, but because [Object Name. attribute name] If you modify the attribute, [Object Name. attribute name] will not be in the same way as [class name. prototype. attribute names] have the same value, which may cause misunderstanding. Therefore, we recommend that you use only the [class name. prototype. attribute name] One way to access. < Script Language = " Javascript " >
Function click_event ()
{
Alert ( " No Instance Object " );
Alert ( " Testclass. Prototype. Count: " + Testclass. Prototype. Count );
Alert ( " Testclass. Prototype. Current: " + Testclass. Prototype. Current. internalname );
VaR testclass1 = New Testclass ();
Alert ( " Instance 1 Object " );
Alert ( " Testclass. Prototype. Count: " + Testclass. Prototype. Count );
Alert ( " Testclass. Prototype. Current: " + Testclass. Prototype. Current. internalname );
VaR testclass2 = New Testclass ( " Jxhwei " );
Alert ( " Two objects of the Instance " );
Alert ( " Testclass. Prototype. Count: " + Testclass. Prototype. Count );
Alert ( " Testclass. Prototype. Current: " + Testclass. Prototype. Current. internalname );
}
</ Script >