📄 object.js
字号:
function uiUtil_Object() { var inherit = arguments[this.__init.length]; if (!inherit) { this.__init.apply(this, arguments); } ++uiUtil_Object.__numOfInstantiatedObjects;}uiUtil_Object.__numOfInstantiatedObjects = 0;uiUtil_Object.prototype.__init = function() {};uiUtil_Object.prototype.__toArray = function(collection, start) { var arr = new Array(); for (var i = start; i < collection.length; ++i) { arr[i - start] = collection[i]; } return arr;};uiUtil_Object.prototype._super = function(optArgN) { this.__apply("__init", this.__toArray(arguments, 0));};uiUtil_Object.prototype._callSuper = function(method, optArgN) { return this.__apply(method, this.__toArray(arguments, 1));};uiUtil_Object.prototype.__apply = function(method, optArguments) { if (this.__executingClass[method] == null) { this.__executingClass[method] = this.constructor; } var currentClass = this.__executingClass[method]; this.__executingClass[method] = currentClass.__parentClass; try { var returnValue = currentClass.__parentPrototype[method].apply(this, optArguments); } finally { this.__executingClass[method] = currentClass; } return returnValue;};uiUtil_Object.prototype.getClassName = function() { return uiUtil_Object.getClassName(this.constructor);};uiUtil_Object.prototype.toString = function() { return this.getClassName() + uiUtil_Object.__numOfInstantiatedObjects;};uiUtil_Object._inherits = function(childClass, parentClass) { var UNDEFINED_VALUE; var count = parentClass.prototype.__init.length; var command = "new parentClass("; if (count > 0) { for (var i = 0; i < count; ++i) { command += "UNDEFINED_VALUE, "; } } command += "true);"; childClass.prototype = eval(command); childClass.prototype.constructor = childClass; childClass.prototype.__executingClass = new Object(); childClass.__parentPrototype = parentClass.prototype; childClass.__parentClass = parentClass; return childClass.prototype;};uiUtil_Object.isAssignableFrom = function(class1, class2) { var currClass = class2; while (currClass != null) { if (class1 == currClass) { return true; } currClass = currClass.__parentClass; } return false;};uiUtil_Object.declareClass = function(origClass, parentClass, optUseLogger) { return uiUtil_Object.__declareGenericClass(origClass, parentClass, ((optUseLogger == null) ? true : optUseLogger), uiUtil_Object.__evaluateClassCode);};uiUtil_Object.declareSingleton = function(origClass, parentClass, optUseLogger) { return uiUtil_Object.__declareGenericClass(origClass, parentClass, ((optUseLogger == null) ? true : optUseLogger), uiUtil_Object.__evaluateSingletonCode);};uiUtil_Object.declareUtil = function(origClass, parentClass) { return uiUtil_Object.__declareGenericClass( origClass, parentClass, false, uiUtil_Object.__evaluateUtilCode);};uiUtil_Object.__declareGenericClass = function( origClass, parent, useLogger, codeGenerator) { try { var classRef = codeGenerator(origClass); var newPrototype = uiUtil_Object._inherits(classRef, parent); newPrototype.__init = origClass; if (useLogger) { newPrototype.__logger = uiUtil_Logger.getInstance(classRef); classRef.__logger = newPrototype.__logger; } } catch (e) { alert("Error declaring class: " + uiUtil_Object.getClassName(classRef) + ".\nCaused by: " + e); } return classRef;};uiUtil_Object.__generateConstructorPrototype = function(origClass) { var className = uiUtil_Object.getClassName(origClass); return "function " + className + "()";};uiUtil_Object.__evaluateUtilCode = function(origClass) { var className = uiUtil_Object.getClassName(origClass); return eval( className + " = " + uiUtil_Object.__generateConstructorPrototype(origClass) + " {" + " throw new uiUtil_CreateException(" + " 'This class is not instantiable: ' + this.getClassName());" + "};" );};uiUtil_Object.__evaluateClassCode = function(origClass) { var className = uiUtil_Object.getClassName(origClass); return eval( className + " = " + uiUtil_Object.__generateConstructorPrototype(origClass) + " {" + " var inherit = arguments[this.__init.length];" + " if (!inherit) {" + " this.__init.apply(this, arguments);" + " }" + "};" );};uiUtil_Object.__evaluateSingletonCode = function(origClass) { var className = uiUtil_Object.getClassName(origClass); return eval( "var temp = " + uiUtil_Object.__generateConstructorPrototype(origClass) + " {" + " if (" + className + ".__instance != null) {" + " throw new uiUtil_CreateException(" + " 'A singleton cannot have multiple instances: ' + className);" + " }" + " " + className + ".__instance = this;" + " var inherit = arguments[this.__init.length];" + " if (!inherit) {" + " try {" + " this.__init.apply(this, arguments);" + " }" + " catch (e) {" + " " + className + ".__instance = null;" + " throw e" + " }" + " }" + "};" + "temp.__instance = null;" + "temp.getInstance = function() {" + " if (" + className + ".__instance == null) {" + " new " + className + "();" + " }" + " return " + className + ".__instance;" + "};" + className + " = temp;" );};uiUtil_Object.getClassName = function(objectClass) { if (objectClass.name == null) { return objectClass.toString().replace( /(.*\n)*function ([^\(]*)\((.*\n)*.*/, "$2"); } return objectClass.name; };uiUtil_Object.getPropertiesString = function(object) { var str = ""; for (property in object) { str += ' ' + property + "=" + this[property]; } return str;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -