<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
<SCRIPT type = "text/JavaScript" src = "jquery. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
VaR page = {};
$ (Document). Ready (function (){
// Alert (typeof page );
});
Function myclass (name ){
// Dynamic propertie
This. Name = Name;
// Dynamic Function
This. showname = function (){
Document. Write (name + "<br/> ");
};
}
Myclass. staticname = "static member ";
// Static method
Myclass. staticfun = function (name ){
Document. Write ("static method return value:" + name + "<br/>" + "staticname:" + myclass. staticname );
};
// When function a's internal function B is referenced by a variable other than function a, a closure is created.
/// // Closure /////////// ///////////////////////////
VaR testcls = function (arg1 ){
// Internal public variables of the object. External access is not allowed.
VaR A = arg1;
VaR B = 10;
VaR alertb = function (){
Alert (B );
}
// Externally accessible regions
Return {
C: 5,
Seta: function (v ){
A = V;
},
Alerta: function (){
Alert ();
},
Alertb: function (){
Alertb ();
}
}
};
VaR test = new testcls (4 );
/*
Test. Seta (6 );
Test. alerta ();
Test. alertb ();
// Alert (test. A); // undefined, with good closeness
Alert (test. c); // 5
*/
//////////////////////////////////////// //////////////////////////////////////// ///
// There is also a controversial format:
// (Function (a, B) {...}) (A, B );
(Function myclass2 (a, B ){
This. myvar = "My variables ";
Alert (A + B + this. myvar );
}) (1, 2 );
</SCRIPT>
</Head>
<SCRIPT type = "text/JavaScript">
VaR MC = new myclass ("Wu xx ");
MC. showname ();
// Static methods can only be referenced by class, not MC. staticfun ("static parameter! ");
Myclass. staticfun ("static parameter! ");
</SCRIPT>
<Body>
</Body>
</Html>