📄 class.js
字号:
return eval(expression); }, //> @classMethod Class.addClassProperties() // // Add static (Class-level) properties and methods to this object<br><br> // // These properties can then be accessed as MyClass.property, or for functions, called as // MyClass.methodName() // // @param [arguments 0-N] (object) objects with properties to add (think named parameters). // all the properties of each argument will be applied // as class-level properties. // @return (object) the class after properties have been added to it // @visibility external //< addClassProperties : function () { isc.addPropertyList(this, arguments); return this; }, //> @classMethod Class.addProperties() // // Add default properties and methods to all instances of this class.<br><br> // // These properties can then be accessed as <code>myInstance.property</code>, // and methods can be called via <code>myInstance.methodName()</code> // // @param [arguments 0-N] (object) objects with properties to add (think named parameters). // all the properties of each argument will be applied // as instance-level property defaults. // @return (object) the class after properties have been added to it // @visibility external //< _deferredDefaults : {}, addProperties : function () { if (this._isInterface) { this.logWarn("Use addInterfaceProperties() to add methods to interface " + this); } isc.addPropertyList(this._instancePrototype, arguments); return this; }, //> @classMethod Class.addPropertyList() // // Add default properties to all instances of this class // // @param list (object[]) array of objects with properties to add // @return (object) the class after properties have been added to it // // @visibility external //< addPropertyList : function (list) { isc.addPropertyList(this._instancePrototype, list); return this; }, //> @classMethod Class.changeDefaults() (A) // // Changes a set of defaults defined as a JavaScript Object. For these kind of properties, // simply calling +link{Class.addProperties()} would replace the original Object // with yours, wiping out settings required for the basic functionality of the component. // This method instead applies your overrides over the existing properties, without // destroying non-overridden properties. // <p> // For example let's say you have a component that's defined as follows // <pre> // isc.defineClass("MyComponent"); // isc.MyComponent.addProperties({ // simpleProperty: "some value", // propertyBlock : { // foo: "bar", // zoo: "moo" // } // } // </pre> // If you wanted to override simpleProperty, you can just call +link{Class.addProperties()} // like this: // <pre> // isc.addProperties(MyComponent, { // simpleProperty: "my override" // }); // </pre> // If you want to override the value of <code>propertyBlock.moo</code> above, // but you don't want to clobber the value of <code>propertyBlock.zoo</code>. If you use // the above pattern like so: // <pre> // isc.addProperties(MyComponent, { // propertyBlock: { // foo: "new value", // zoo: "moo" // } // }); // </pre> // You need to re-specify the value of <code>propertyBlock.zoo</code> which you didn't want // to override. Failing to respecify it would destroy the value. // <p> // Instead of re-specifying the value, you can use this method to modify the value of // <code>foo</code> - like this: // <pre> // isc.changeDefaults(MyComponent, "propertyBlock", { // foo: "new value" // }); // </pre> // <p> // A typical pattern for creating a custom component with overrides only is to create a // subclass of the component you want to customize and then call // <code>changeDefaults()</code> to modify override points that are specified as object // literals. // <p> // SmartClient components that accept overrides in this manner will typically document what // properties are overrideable. // // @param defaultsName (String) name of the property to change // @param newDefaults (Object) The new default(s) // // @visibility external //< changeDefaults : function (defaultsName, newDefaults) { // get existing defaults var defaults = this._getDefaults(defaultsName), mustAssign = false; // if we have a superclass with the same defaults, copy them so the superclass is not // affected var mySuper = this.getSuperClass(); if (mySuper) { var superDefaults = mySuper._getDefaults(defaultsName); if (superDefaults != null && superDefaults == defaults) { //this.logWarn("copying defaults for property: " + defaultsName + // " on class: " + this); defaults = isc.addProperties({}, defaults); mustAssign = true; } } // if defaults don't exist, create an empty object for them if (defaults == null) { defaults = newDefaults || {}; mustAssign = true; } else { // otherwise add the specified defaults to the existing defaults isc.addProperties(defaults, newDefaults); } // if we created a new defaults object (because there were no existing defaults, or we // had to duplicate a superclass' defaults) override the slot on this class if (mustAssign) { //this.logWarn("had to assign when overriding property: " + defaultsName + // " on class: " + this); var props = {}; props[defaultsName] = defaults; this.addProperties(props); } }, _getDefaults : function (defaultsName) { var deferredDefaults = this._deferredDefaults[this.Class], defaults = this.getInstanceProperty(defaultsName) || (deferredDefaults ? deferredDefaults[defaultsName] : null); return defaults; }, // backcompat: briefly exposed as visibility external in 5.5 beta builds replaceDefaults : function (defaultsName, newDefaults) { this.changeDefaults(defaultsName, newDefaults); }, //> @classMethod Class.setProperties() // Apply a set of properties to a class object, calling the appropriate setter class methods if // any are found. // // @param [arguments 0-N] (object) objects with properties to add (think named parameters). // all the properties of each argument will be applied one after another // so later properties will override // @visibility external //< setProperties : function () { var propertyBlock; // If passed multiple arguments, combine them down to a single object. // (Step required as setProperties() on this instance prototype doesn't take an array, // and we don't know how many arguments we have). if (arguments.length == 1) { propertyBlock = arguments[0]; } else { propertyBlock = {}; for (var i = 0; i < arguments.length; i++) { isc.addProperties(propertyBlock, arguments[i]); } } // set properties on the instance prototype this._instancePrototype.setProperties(propertyBlock); }, //> @classMethod Class.isOverridden() // Determine whether we've overridden a specified class property or method from our superClass // // @param property (string) property to check // // @return (boolean) true if the property has been overridden //< isOverridden : function (property) { // XXX Note - need another function to check for a class overriding the properties of the // instance prototype return (!(this[property] === this._superClass[property])); }, //> @classMethod Class.isA() // // Returns whether this class object is the provided class or is a subclass of the provided // class, or implements the provided interface. // // @param className (string) Class name to test against // // @return (boolean) true == this Class is a subclass of the provided classname // @visibility external //< isA : function (className) { if (className == null) return false; // handle being passed Class Objects and instances of classes if (!isc.isA.String(className)) { className = className.Class; if (!isc.isA.String(className)) return false; } if (isc.startsWith(className, isc.ClassFactory._$iscPrefix)) { className = className.substring(4); } // walk the class object inheritance chain var superClass = this; while (superClass) { if (superClass.Class == className) return true; superClass = superClass._superClass; } // walk the interface inheritance chain if (this._implements) { for (var i = 0; i < this._implements.length; i++) { var superInterface = isc.ClassFactory.getClass(this._implements[i]); while (superInterface) { if (superInterface.Class == className) return true; superInterface = superInterface._superClass; } } } return false; }, _getNextImplementingSuper : function (methodCallingSuper, superClassProto, methodName, staticSuper) { var superClassImpl; for (;;) { if (superClassProto == null) { // no superclass provides a differing implementation - error superClassImpl = null; break; } var superClassImpl = isc.Class._getOriginalMethod(methodName, superClassProto); // function is not defined in any superclass further up the chain - error if (superClassImpl == null) break; // found a superclass implementation that differs - success! if (methodCallingSuper != superClassImpl) { //this.logWarn("found differing superClass implementation: " + // this.echoLeaf(superClassImpl) + // " on prototype: " + superClassProto); break; } // go up the chain to the prototype of the superClass if (staticSuper) { superClassProto = superClassProto._superClass; } else { superClassProto = superClassProto._classObject._superClass._instancePrototype; } } if (superClassImpl != null) return superClassProto; return null; }, //> @classMethod Class.Super() // // Call the SuperClass implementation of a class method. // // @param methodName (string) name of the superclass method to call // @param args (arguments or Array) native "arguments" object, or array of // arguments to pass to the Super call // @param [nativeArgs] (arguments) native "arguments" object, required if an Array is // passed for the "args" parameter in lieue of the native // arguments object // // @return (any) return value of the superclass call // // @visibility external //< // @param [nativeArguments] (Arguments) native "arguments" object. Required only if // calling Super() with a substitute set of // arguments Super : function (methodName, args, nativeArguments) { if (isc._traceMarkers) arguments.__this = this; // if args is clearly not an Array or Arguments object, make it an Array. NOTE: you // can still fool us by passing an object with a .length property which is neither an // Array or Arguments object - to avoid this we'd have to be able to reliably // cross-platform tell the difference between an Arguments object and a normal Object. // The simplest way to do this would probably be to check the callee property, which is // very unlikely to be set to a function on some random object being passed as params. if (args != null && (args.length == null || isc.isA.String(args))) args = [args]; if (args == null) args = isc._emptyArray; this._nativeArguments = nativeArguments || args;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -