Copy codeThe Code is as follows:
$ Defined = function (v ){
Return v! = Undefined;
}
Class = function (){
Var base = {};
For (var k = 0; k <arguments. length; k ++ ){
// {New arguments [k] () with custom constructor field.
Var o = arguments [k]. prototype;
O. constructor = arguments [k];
Arguments [k]. call (o );
//}}
For (key in o) base [key] = o [key];
}
Function Klass (){
// For every class one object cache.
Var clso = null;
Function klass (){
If (arguments. length <= 0 & clso! = Null ){
// Hit cache.
Return clso;
}
If ($ defined (this. constructor. init )){
// Use init () for class initialization.
This. constructor. init. apply (this, arguments );
}
Clso = this;
}
Klass. prototype = base;
Return klass;
}
Return Klass ();
}
A = new Class ();
A. init = function (){
This. x = 400;
This. y = 300;
}
B = new Class ();
B. init = function (){
This. y = 200;
This. z = 100;
}
C = new Class (B );
C. init = function (){
This. z = 0;
}
C = new C ();
Alert (c. x );
Alert (c. y );
Alert (c. z );