⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classfactory.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 3 页
字号:
        		// now assign the object under that ID globally so anyone can call it		wd[object.ID] = object;            // simple mechanism for instrumenting globals capture.  Simply set isc.globalsSnapshot to an        // array and we'll fill it here.                 if (isc.globalsSnapshot) isc.globalsSnapshot.add(object.ID);        	},    _$isc_OID_ : "isc_OID_",    _$isc_ : "isc_",    _$underscore : "_",    _joinBuffer : [],    getNextGlobalID : function (object) {        if (object != null && isc.isA.String(object.Class)) {            var buffer = this._joinBuffer;            buffer[0] = this._$isc_;            buffer[1] = object.Class;            buffer[2] = this._$underscore;            isc._fillNumber(buffer, this._globalObjectID++, 3, 5);            var result = buffer.join(isc.emptyString);            return result;        }        return this._$isc_OID_ + this._globalObjectID++;    },    _domIDCount:0,    _$isc_:"isc_",    _simpleDOMIDTemplate:[null, "_", null],    getDOMID  : function (ID, suffix) {                // By default we return a unique but uninformative ID like "isc_1A"                if (!isc._longDOMIds || !ID || !suffix) {            var number = this._domIDCount++;            return this._convertToBase36(number, this._$isc_);        }                // In simpleDOMIDMode, create an ID that incorporates the ID / suffix passed to us        // We're making an assumption that the ID / suffix passed in is already unique                this._simpleDOMIDTemplate[0] = ID;        this._simpleDOMIDTemplate[2] = suffix;        return this._simpleDOMIDTemplate.join(isc.emptyString);    },        _base36Digits:["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K",                   "L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],    _base36Arr:[],    _convertToBase36 : function (number, prefix) {        var digits = this._base36Digits,            resultsArr = this._base36Arr;        resultsArr.length = 0;        // We use this to prefix with "isc_"        if (prefix) resultsArr[0] = prefix;                var totalDigits = 3;                if (number > 46655) {            while (Math.pow(36,totalDigits) <= number) totalDigits += 1;        }                // convert number to base 36        while (number >= 36) {            var remainder = number % 36;            // always add to the end slot, so we get 100 rather than 001            resultsArr[totalDigits-(prefix ? 0 : 1)] = digits[remainder];            totalDigits -=1;                        number = Math.floor(number / 36);        }        resultsArr[totalDigits-(prefix ? 0 : 1)] = digits[number];           return resultsArr.join(isc.emptyString);            },    	//>	@classMethod	ClassFactory.mixInInterface()	(A)	//	// Add the methods of a given Interface to a Class so the class implements the methods.    // If the class has already defined a method with the same name as the one specified	// in the interface, the class' method will be retained.	//	//	@param	className		(String)	Name of the Class to add methods to.	//	@param	interfaceName	(String)	Name of the Interface to get methods from.	//<	mixInInterface : function (className, interfaceName) {		var theInterface = this.getClass(interfaceName),			theClass = this.getClass(className)		;		if (!theInterface || !theClass) return null;			if (!theInterface._isInterface) {			//>DEBUG			isc.Log.logWarn("ClassFactory.mixInInterface asked to mixin a class which was not"						+ " declared as an Interface: "+interfaceName+ " onto "+className);			//<DEBUG            return;		}		// mark the class as implementing the interface		if (!theClass._implements) theClass._implements = [];        // ensure the interface doesn't apply to a superClass        else theClass._implements = theClass._implements.duplicate();        // install all properties and methods added to this interface, and any superInterfaces        while (theInterface) {    		// mix in class properties and methods	    	this._mixInProperties(theInterface, theClass, true);    		// mix in instance properties and methods	    	this._mixInProperties(theInterface, theClass);		    theClass._implements[theClass._implements.length] = interfaceName;            theInterface = theInterface.getSuperClass();            if (theInterface && !theInterface._isInterface) break;        }	},	_mixInProperties : function (source, destination, asClassProperties) {        var props;		if (asClassProperties) {             props = isc._interfaceClassProps[source.Class];		} else {            props = isc._interfaceInstanceProps[source.Class];			source = source.getPrototype(); 			destination = destination.getPrototype();        }        if (props == null) return;        for (var i = 0; i < props.length; i++) {            var propName = props[i];			// skip any properties already defined in the target			if (destination[propName] != null) continue;                var propValue = source[propName];			// the interface declared that the target class must implement a method, and it's not			// there			if (isc.isA.String(propValue) && propValue == this.TARGET_IMPLEMENTS) {				//>DEBUG				var message = (asClassProperties ? "Class" : "Instance") + " method " 					+ propName + " of Interface " + source.Class + " must be implemented by "					+ "class " + destination.Class;                // Don't complain about interface methods not being implemented b/c it's                // perfectly normal to mix in interfaces before adding properties to the                // class.  In fact that may be the case most of the time b/c showing the                // interfaces at class definition is very useful                 // (e.g: defineClass("Foo", "Bar", "SomeInterface")				//				//isc.Log.logWarn(message + ", is not yet implemented"); 				// but it will be an error if this method is ever called, so install a function                // that will complain				destination[propName] = new Function('this.logError("' + message + '")');				//<DEBUG 			} else {                //isc.Log.logWarn("adding property " + propName +                 //                " from interface " + source.Class);				destination[propName] = propValue;            }        }	},	//>	@classMethod	ClassFactory.makePassthroughMethods()	(A)	//    // Create methods that call through to a related object stored under property    // <code>propName</code>.  This enables easy implementation of the Delegate design    // pattern, where one object implements part of its APIs by having another object respond    // to them.    // 	//	@param	methodNames	(array of strings)	list of methods names	//	@param	propName    (string)		    Property name where the target object is stored.	//<    _$argList : "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p",    makePassthroughMethods : function (methodNames, propName) {        if (!propName) propName = "parentElement";        var funcTemplate = this._funcTemplate;        if (funcTemplate == null) {            funcTemplate = this._funcTemplate = ["return this.",,".",,"("+this._$argList+")"];        }        var methods = {};		for (var i = 0; i < methodNames.length; i++) {			var methodName = methodNames[i];    			// create a function that routes a function call to the target object            funcTemplate[1] = propName;            funcTemplate[3] = methodName;			methods[methodName] =                 new Function(this._$argList, funcTemplate.join(isc.emptyString));		}                return methods;    },	//>	@classMethod	ClassFactory.writePassthroughFunctions()	(A)    //    // Install methods in <code>destinationClass</code> which will call the same-named function    // on a related object stored under the property name <code>memberName</code> on instances    // of <code>destinationClass</code>.    //	//	@example	<code>ClassFactory.writePassthroughFunctions(	//					ListGrid, "selection", ["select","selectAll",..."]	//				);</code>	//	//				after this, you can call	//					listGrid.selectRecord()	//				rather than	//					listGrid.selection.selectRecord()    //<	writePassthroughFunctions : function (destinationClass, memberName, methodNames) {        var methods = this.makePassthroughMethods(methodNames, memberName);        destinationClass.addMethods(methods);    }});	// END isc.addMethods(isc.ClassFactory)//// add properties to the ClassFactory object//isc.addProperties(isc.ClassFactory, {	// when defining interfaces, use this constant as a marker value indicating that a method    // must be implemented by any class your interface is mixed in to	TARGET_IMPLEMENTS : "TARGET_IMPLEMENTS",	//>	@attr	ClassFactory.defaultSuperClass  (Class : null : [IA])      // Class to use as the default superClass if none is specified    //<			// Counter which is used to generate unique object IDs	_globalObjectID : 0,	// Classes created with ClassFactory.defineClass	classList : []});//> @classMethod isc.defineClass// Shortcut for <code>isc.ClassFactory.defineClass()</code>.// @include classMethod:ClassFactory.defineClass// @see ClassFactory.defineClass()//<isc.defineClass = function (className, superClass, interfaces, suppressSimpleName) {    return isc.ClassFactory.defineClass(className, superClass, interfaces, suppressSimpleName);}isc.defer = function (code) {    var lastClass = isc.ClassFactory.getClass(isc.ClassFactory.classList.last()),        existingCode = lastClass._deferredCode;    isc.Log.logWarn("deferred code being placed on class: " + lastClass);    // first time    if (!existingCode) lastClass._deferredCode = [code];    // more times    else existingCode.add(code);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -