1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
| <!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>UID Class System</title>
<style>
</style>
<script type="text/javascript" src="UID.js"></script>
<script type="text/javascript">
//basic class definition
UID.Class.define('test1', {
constructor : function(ar1){
this.ar1 = ar1;
alert('construcor of test1');
},
destructor : function(){
alert('destructor of test1');
delete this.ar1;
},
Static : {
myStaticPublicMethod : function(){
alert('StaticPublicMethod');
},
_myStaticProtectedMethod : function(){
alert('StaticProtectedMethod');
},
__myStaticPrivateMethod : function(){
alert('StaticPrivateMethod');
}
},
myPublicMethod : function(){
alert('PublicMethod');
},
_myProtectedMethod : function(){
alert('ProtectedMethod');
},
__myPrivateMethod : function(){
alert('PrivateMethod');
}
});
//var myTest = new test1('ok');
//singleton class definition
UID.Class.define('test1', {
Singleton : true,
constructor : function(ar1){
this.ar1 = ar1;
alert('construcor of test1');
},
destructor : function(){
alert('destructor of test1');
delete this.ar1;
}
});
//var myTest = new test1('ok'); throw error
//var myTest = test1.getInstance('ok'); ok
//inheritance diamond, and self use
UID.Class.define('test1', {
constructor : function(ar1){
this.ar1 = ar1;
alert('construcor of test1');
this.self(arguments).myStaticPublicMethod();
},
destructor : function(){
alert('destructor of test1');
delete this.ar1;
},
Static : {
myStaticPublicMethod : function(){
alert('StaticPublicMethod');
}
}
});
UID.Class.define('test2', {
Extends : test1,
constructor : function(ar2){
this.ar2 = ar2;
alert('construcor of test2');
},
destructor : function(){
alert('destructor of test2');
delete this.ar2;
}
});
UID.Class.define('test3', {
Extends : test1,
constructor : function(ar3){
this.ar3 = ar3;
alert('construcor of test3');
},
destructor : function(){
alert('destructor of test3');
delete this.ar3;
}
});
UID.Class.define('test4', {
Extends : [test2, test3],
constructor : function(ar1, ar2, ar3, ar4){
this.ar4 = ar4;
alert('construcor of test4');
},
destructor : function(){
alert('destructor of test4');
delete this.ar4;
}
});
//var myTest = = new test4('argument1', 'argument2', 'argument3', 'argument4');
//myTest.destruct();
//use inheritance function
UID.Class.define('test1', {
constructor : function(ar1){
this.ar1 = ar1;
},
destructor : function(){}
});
UID.Class.define('test2', {
constructor : function(ar1){},
destructor : function(){}
});
// dynamic inheritance
test2.extend(test1);
// dynamic definition
test2.mixin({
myAttribute : 'ok',
myMethhode : function(){}
});
test2.isAncestor(test1); // -> true
test1.isDescendant(test2); // -> true
test2.getAncestors(); // -> [Class Object, Class test1]
test1.getDescendants(true); // -> test1
var myTest = new test2('ar1');
test1.isInstanceOf(myTest); // -> true
</script>
</head>
<body>
</body>
</html> |
Partager