Changeset 26
- Timestamp:
- 11/25/05 11:05:58 (3 years ago)
- Files:
-
- trunk/jsolait/jsolait.js (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/jsolait/jsolait.js
r23 r26 61 61 //set up the 'public static' fields of the class 62 62 var __class__={__isArray__ : false, 63 __name__ : name,64 __bases__: bases,65 __id__:classID,66 __hash__: function(){67 return this.__id__;68 },69 __str__ : function(){63 __name__ : name, 64 __bases__: bases, 65 __id__:classID, 66 __hash__: function(){ 67 return this.__id__; 68 }, 69 __str__ : function(){ 70 70 return "[class %s]".format(this.__name__); 71 }71 } 72 72 }; 73 73 … … 79 79 return "[%s %s]".format(this.__class__.prototype.__call__ === undefined ? 'object' : 'callable', this.__class__.__name__); 80 80 }; 81 //because toString is not apearing in a for in loop we will just use __str__ and always assign it to toString82 //this makes prototype creatin a bit simpler83 proto.toString=proto.__str__;84 81 __class__.__bases__=[Object]; 85 82 }else{ //inherit from all base classes 86 //inheritance is done by87 83 var baseProto; 88 84 for(var i=0;i<bases.length;i++){ … … 114 110 } 115 111 } 116 //make sure the toString points to __str__, this will make overwriting __str__ after object construction impossible (todo ?)117 //but will be faster than having toString call __str__, also overwriting methods unless they are ment to be overridden is not cool anyways.118 proto.toString=proto.__str__;119 112 } 120 113 //make sure all jsolait objects have a hash method … … 129 122 proto.__class__=__class__; 130 123 131 var privId = '__priv__' + __class__.__id__; 132 133 //run teh class setup function provided as classScope 124 //run the class setup function provided as classScope 134 125 if(classScope.length-1 > baseProtos.length){ 126 var privId = '__priv__' + __class__.__id__; 135 127 classScope.apply(this,[proto, privId].concat(baseProtos)); 136 128 }else{ 137 129 classScope.apply(this,[proto].concat(baseProtos)); 138 130 } 139 131 132 //make sure the toString points to __str__, this will make overwriting __str__ after object construction impossible (todo ?) 133 //but will be faster than having toString call __str__, also overwriting methods unless they are ment to be overridden is not cool anyways. 134 proto.toString=proto.__str__; 135 140 136 //allthough a single constructor would suffice for generating normal objects, Arrays and callables, 141 137 //we use 3 different ones. This will minimize the code inside the constructor and therefore … … 212 208 proto.constructor = NewClass; 213 209 proto.__class__= NewClass;//no, it is not needed, just like __str__ is not, but it is nicer than constructor 214 210 215 211 //this is where the inheritance realy happens 216 212 NewClass.prototype = proto; … … 225 221 }; 226 222 Class.__idcount__=0; 227 Class.toString = function(){ 228 return "[object Class]"; 229 }; 230 231 Class.__createProto__=function(){ 232 throw "Can't use Class as a base class."; 233 }; 223 Class.__str__=Class.toString = function(){return "[object Class]";}; 224 Class.__createProto__=function(){ throw "Can't use Class as a base class.";}; 234 225 235 226 Array.__isArray__=true; … … 237 228 Array.__createProto__=function(){ var r =[]; r.__str__ = Array.prototype.toString; return r; }; 238 229 Object.__str__=Object.toString=function(){return "[class Object]";}; 239 Function.__createProto__ = function(){ throw "Cannot inherit from Function. implement the callabel interface instead using YourClass::__call__.";}; 240 241 230 Function.__createProto__ = function(){ throw "Cannot inherit from Function. implement the callable interface instead using YourClass::__call__.";}; 242 231 243 232 /** … … 370 359 Module("jsolait", "$Revision$", function(mod){ 371 360 jsolait=mod; 372 361 373 362 mod.modules={}; 374 363
