📄 class.js
字号:
/*
* Isomorphic SmartClient
* Version 6.5 (2008-04-30)
* Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
* "SmartClient" is a trademark of Isomorphic Software, Inc.
*
* licensing@smartclient.com
*
* http://smartclient.com/license
*/
if (!isc.Browser.isSafari) { isc._window = window; isc._document = window.document;}//> @class Class// // The Class object is root of the Isomorphic SmartClient inheritance tree -- it includes// functionality for creating instances, adding methods and properties, getting prototypes,// etc.<br><br>//// To add functionality to ALL classes, add them to Class.<br><br>//// To create a Class, call <code>ClassFactory.defineClass("MyClass", "MySuperClass")</code>// <P>// <code>defineClass</code> will return the created class, and make it available as// <code>isc.MyClass</code>, and as the global variable <code>MyClass</code> if not in// +link{class:isc,portal mode}.// <P>// You can then:// <UL>// <LI>add class-level (static) properties and methods to the class:// <code>MyClass.addClassProperties()</code> // these methods and properties are accessed through the Class variable itself, eg:// <code>MyClass.someStaticMethod()</code> or <code>MyClass.someStaticProperty</code>//// <LI>add default instance properties and methods to the class:// <code>MyClass.addProperties()</code>// these methods and properties are accessed through a class instance, eg:// <code>var myInstance = MyClass.create();</code>// <code>myInstance.someInstanceMethod()</code>//// <LI>create new instances of this class:// <code>var myInstance = MyClass.create()</code>// </UL>// NOTE: as a convention, all class names begin with a capital letter and all instances begin// with a lower case letter.//// @treeLocation Client Reference/System// @visibility external//<isc.ClassFactory.defineRootClass('Class');//// set Class as the default superclass for classes defined by ClassFactory.defineClass()//isc.ClassFactory.defaultSuperClass = isc.Class;//// add static methods to all classes defined with our system//// call on the Class object itself, as: Class.method()//// First we install the methods that allow us to addMethods to a class as a method call on the// class (eg Class.addClassMethods(methods) rather than addMethods(Class, methods);.isc.addMethods(isc.Class, { //> @classMethod Class.addClassMethods() // // Add static (Class-level) methods to this object.<br><br> // // These methods can then be called as MyClass.method(). The value for "this" will be the // class object for the class. // // @param [arguments 0-N] (object) objects with methods to add (think named parameters). // all the methods of each argument will be applied // as class-level methods. // @visibility internal //< addClassMethods : function () { for (var i = 0; i < arguments.length; i++) isc.addMethods(this, arguments[i]); } });isc.Class.addClassMethods({ //> @classMethod Class.create() // // Create an instance of this class. // <P> // All arguments passed to this method are passed on to the +link{Class.init()} instance // method. Unless +link{class.addPropertiesOnCreate} is set to <code>false</code>, all // arguments passed to this method must be Objects and all properties on those // objects will be copied to the newly created instance before +link{Class.init()} is // called. If there are overlapping properties in the passed arguments, the last wins. // <p> // Any return value from +link{Class.init()} is thrown away. // <p> // Note: Generally, you would not override this method. If you want to specify a // constructor for your class, provide an override for +link{Class.init()} for generic // classes or +link{canvas.initWidget()} for any subclasses of UI components // (i.e. descendants of +link{Canvas}. // // @param [arguments 0-N] (any) // Any arguments passed will be passed along to the init() routine of the instance. // Unless +link{class.addPropertiesOnCreate} is set to false, any arguments passed to // this method must be of type Object. // @return (object) // New instance of this class, whose init() routine has already been called // // @example <code>var myInstance = MyClass.create()</code> // @example create // @visibility external //< create : function (A,B,C,D,E,F,G,H,I,J,K,L,M) { var newInstance = this.createRaw(); newInstance = newInstance.completeCreation(A,B,C,D,E,F,G,H,I,J,K,L,M); // return the new instance return newInstance }, _initializedClasses : {}, createRaw : function () { if (!this.initialized()) this.init(); // create a new instance based on the class's instanceProtoype var newInstance = new this._instancePrototype._instanceConstructor(); // install the appropriate namespace on the instance newInstance.ns = this.ns; return newInstance; }, // class-level init init : function () { //this.logWarn("uninitialized class"); // init superclass chain var superClass = this.getSuperClass(); if (superClass && !superClass.initialized()) superClass.init(); // execute any deferred class definition var deferredCode = this._deferredCode; if (deferredCode) { //this.logWarn("eval'ing deferred code"); this._deferredCode = null; deferredCode.map(eval); } this._initializedClasses[this.Class] = true; }, // NOTE: we have to use a structure like this instead of just checking a property on the // class object (eg this._initialized) because any property would be inherited from // superclass class objects. initialized : function () { return this._initializedClasses[this.Class] }, //> @classMethod Class.getClassName() // // Gets the name of this class as a string. // // @return (string) name of the class // @visibility external //< getClassName : function () { return this.Class; }, //> @classMethod Class.getSuperClass() // // Gets a pointer to the superClass' Class object. // // @return (Class) Class object for superclass. // @visibility external //< getSuperClass : function () { return this._superClass; }, //> @classMethod Class.getPrototype // // Gets a pointer to the prototype object for this class. // // This is the object that you should install methods/properties into // to have them apply to each instance. Generally, you should use // +link{Class.addProperties()} to do this // rather than affecting the prototype directly // // @return (object) Prototype for all objects instances. //< // NOTE: not external because customers shouldn't muck with the prototype directly getPrototype : function () { return this._instancePrototype; }, //> @classMethod Class.addMethods() // // Add methods to all instances of this class.<br><br> // // The added methods can be called as myInstance.method() // // @param [arguments 0-N] (object) objects with methods to add (think named parameters). // all the methods of each argument will be applied // as instance-level methods. // @return (object) the class after methods have been added to it // @visibility internal //< addMethods : function () { if (this._isInterface) { this.logWarn("Use addInterfaceMethods() to add methods to interface " + this); } for (var i = 0; i < arguments.length; i++) isc.addMethods(this._instancePrototype, arguments[i]); return this._instancePrototype; }, addInterfaceMethods : function () { for (var i = 0; i < arguments.length; i++) isc.addMethods(this._instancePrototype, arguments[i]); }, addInterfaceProperties : function () { isc.addPropertyList(this._instancePrototype, arguments); }, //> @classMethod Class.registerStringMethods() // // Register a method, or set of methods, that can be provided to instances of this class as // Strings (containing a JavaScript expression) and will be automatically converted into // functions. // <p> // For example: // <pre> // isc.MyClass.registerStringMethods({ // myStringMethod: "arg1, arg2" // }); // </pre> // // @param methodName (object) If this is a string, name of the property to register // If this is an object, assume passing in a set of name/value // pairs to register // @param argumentString (string) named arguments for the property in a comma separated string // (not used if methodName is an object) // @visibility external //< registerStringMethods : function (methodName, argumentString) { // If we haven't already done so, override the method argument registry // from the super class (otherwise we'll affect other classes with our changes) var registry = this._stringMethodRegistry; if (!this.isOverridden("_stringMethodRegistry")) { //if (registry._entries != null) { // this.logWarn("Methods being registered on: " + this.Class + // " causing copy of superclass " + this._superClass.Class + // " registry"); //} var registryClone = {}, entries = registryClone._entries = (registry._entries ? registry._entries.duplicate() : []); for (var i = 0; i < entries.length; i++) { registryClone[entries[i]] = registry[entries[i]]; } this._stringMethodRegistry = registry = registryClone; } // If it's an object, rather than a string, assume it's a list of multiple methodName // to argument mappings to register at once. if (!isc.isA.String(methodName)) { var newMethods = methodName; // if it's not an object, bail - we don't know how to deal with this if (!isc.isAn.Object(newMethods)) { this.logWarn("registerStringMethods() called with a bad argument: " + methodName); return false; } for (var methodName in newMethods) { registry[methodName] = newMethods[methodName] registry._entries.add(methodName); } } else { // in the registry, the distinction between null and undefined is important. // If the second parameter is currently undefined, set it to null // (this allows the second param. to be optional). if (argumentString == null) argumentString = null; registry[methodName] = argumentString; registry._entries.add(methodName); } // return true for success return true; }, //> @classMethod Class.evaluate() // // Evaluate the given expression in the context of the window the libraries are loaded in. // // @param expression (string) the expression to be evaluated // // @return (any) the result of the eval //< // NOTE: not external because you only need this for complex cross-frame scripting evaluate : function (expression) { //!OBFUSCATEOK
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -