<Htm>
<Head>
<SCRIPT>
// Define a javascript class
Function jsclass (privateparam/**/, publicparam) {// Constructor
VaR primember = privateparam; // Private variable
This. pubmember = publicparam; // public variable
// Define a private Method
Function primethod (){
Return "primethod ()";
}
// Define the privileged method
// The privileged method can access all members.
This. privilegedmethod = function (){
VaR STR = "this is a privileged method. I called/N ";
STR + = "private variable:" + primember + "/N ";
STR + = "Private method:" + primethod () + "/N ";
STR + = "Public variable:" + this. pubmember + "/N ";
STR + = "public method:" + this. pubmethod ();
Return STR;
}
}
// Add public methods
// Private variables and methods cannot be called
Jsclass. Prototype. pubmethod = function (){
Return "pubmethod ()";
}
// Instances using jsclass
Jsobject = new jsclass ("primember", "pubmember ");
// Alert (jsobject. pubmember); // The pubmember information is displayed.
// Alert (jsobject. primember); // The undefined information is displayed.
// Alert (jsobject. pubmethod (); // The pubmethod information is displayed.
// Alert (jsobject. primethod (); // The error "the object does not support this attribute or method" is displayed.
Alert (jsobject. privilegedmethod ());
</SCRIPT>
</Head>
<Body>
</Body>
</Htm>