📄 object.js
字号:
//// </pre>Combining settings in order of precedence:<pre>//// isc.addProperties({}, defaults, overrides, skinOverrides);//// </pre>// <P>// <b>NOTE</b>: do not use <code>addProperties</code> to add defaults to an ISC class. Use// <code>Class.addProperties()</code>, as in: <i>MyClassName</i><code>.addProperties()</code>.//// @see Class.addProperties() //// @param destination (object) object to add properties to// @param [(arguments 1-N)] (object) objects to obtain properties from. Properties of all // arguments other than destination are applied in turn.// @return (object) returns the destination object// @visibility external//</*// code to count all methods according to what they are added toisc.methodCount = 0;isc.classMethodCount = 0;isc.otherMethods = 0;isc.otherMethodTargets = [];*/isc._sourceList = [];isc.addGlobal("addProperties", function (destination, 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) { var undef, sourceList = isc._sourceList; if (X === undef && Y=== undef && Z === undef) { isc.fillList(sourceList, 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); } else { sourceList.length = 0; for (var i = 1; i < arguments.length; i++) { sourceList[i -1] = arguments[i]; } } var result = isc.addPropertyList(destination, sourceList); // reset the sourceList so we don't hang onto the objects in memory unnecessarily sourceList.length = 0; return result; });isc._interfaceInstanceProps = {};isc._interfaceClassProps = {};isc._getInterfaceProps = function (destination) { var className = destination.Class, props; if (isc.isA.ClassObject(destination)) { props = isc._interfaceClassProps[className] = isc._interfaceClassProps[className] || []; } else if (isc.isAn.InstancePrototype(destination)) { props = isc._interfaceInstanceProps[className] = isc._interfaceInstanceProps[className] || []; } return props;}//> @method ClassFactory.addPropertyList() or isc.addPropertyList()//// Add all properties from any number of objects to a destination object.//// This differs from addProperties() in that it takes an array as it's second argument,// applying each object in the array as properties in turn. //// @param destination (object) object to add properties to// @param sourceList (array) array of objects with properties to add// @return (object) the object after properties have been added to it//<isc.addPropertyList = function (destination, sourceList) { // Don't JS error if passed a null destination if (destination == null) { if (isc.Log) isc.Log.logWarn("Attempt to add properties to a null object. " + "Creating a new object for the list of properties." ); destination = {}; } var methods, // detect functions being added as properties. Doesn't work until after "isA" has // initialized checkFunctions = (isc.isA != null), // get the registry of string methods on the destination object registry = (isc.isAn && isc.isAn.Instance(destination) ? destination.getClass()._stringMethodRegistry : destination._stringMethodRegistry); if (registry == null) registry = isc.emptyObject; var props = destination._isInterface ? isc._getInterfaceProps(destination) : null; for (var i = 0, l = sourceList.length; i < l; i++) { // add it's properties to the destination var source = sourceList[i]; // if <code>source</code> is null, skip it. if (source == null) continue; // copy properties from source to destination for (var propName in source) { var propValue = source[propName]; // if any of source's properties are functions // or any of the source's properties are registered as stringMethods on the // destination object // use addMethods to copy these properties var undefined; // Check for functions / stringMethods as appropriate. if (registry[propName] !== undefined || (checkFunctions && isc.isA.Function(propValue))) { if (methods == null) methods = {}; methods[propName] = propValue; // don't copy an identical property // NOTE: unsafe: a subclass may wish to set a property to the same value as the // default for its superclass, and have the subclass value remain unchanged // if the superclass default is changed. //} else if (!(source[property] === destination[property])) { } else { if (props != null) props[props.length] = propName; // check for clobbering a function with a non-function value, eg setting // Canvas.enable:false. if (isc.Log != null && checkFunctions && (!isc.isA.Function(propValue) && isc.isA.Function(destination[propName]))) { isc.Log.logWarn("method " + propName + " on " + destination + " overriden with non-function: '" + propValue + "'"); } destination[propName] = propValue; /* } else { if (destination.Class && isc.Log && (!isc.isAn.Instance(destination) || destination._prototype === destination)) { isc.Log.logWarn("needless override on class: " + destination.Class + ": " + propName + "->" + propValue); } */ } } } if (methods != null) isc.addMethods(destination, methods); return destination;}//> @method isc.addMethods()//// Add all named methods from <code>source</code> to <code>destination</code> //// @see addProperties()//// @param destination (object) object to add methods to// @param source (object) object to get methods from// @return (object) the object after methods have been added to it////<// NOTE: not externally documented since there is essentially no legitimate reason for author// code to use this instead of Class.addMethods().isc._$string = "string";isc._$function = "function";isc._$constructor = "constructor";isc._$object = "object";isc.addGlobal("addMethods", function (destination, source) { if (!destination || !source) return destination; var props = destination._isInterface ? isc._getInterfaceProps(destination) : null; if (!isc.__remap) isc.__remap = {}; for (var name in source) { if (props != null) props[props.length] = name; var method = source[name]; // if a method was specified as a string or an action-object, see if the // destination defines this as a legal string method. // NOTE: check typeof object to support Actions, but check non-null because // typeof null == "object" and null specified for a method should wipe it out. if (isc.isAn.Instance != null && method != null && (typeof method == isc._$string || typeof method == isc._$object)) { var registry = (isc.isAn.Instance(destination) ? destination.getClass()._stringMethodRegistry : destination._stringMethodRegistry); var undefined; // check for undefined rather than null if (registry && !(registry[name]===undefined) && name != isc._$constructor) { method = isc.Func.expressionToFunction(registry[name], source[name]); } // XXX If it's not a function or a stringMethod, assume it's ok to add it using the // addMethods logic rather than booting back to addProperties } // If someone's observing this method, the actual method will be stored under a different // name var observers = destination._observers, finalName = (observers != null && observers[name] != null ? isc._obsPrefix + name : name); // If the method is already in the correct slot, we're done. if (method !== destination[finalName]) { if (method != null) { //>DEBUG take the opportunity to label the function with a name for debug // purposes. this._nameMethod(method, name, destination) //<DEBUG } destination[finalName] = method; if (method != null) { // if the method was previously assigned an obfuscated name, make sure the function is // available under the obfuscated name in the object it's being mixed into if (isc.__remap[name]) { // same check for observation applies here var finalObfName = (destination._observers != null && destination._observers[isc.__remap[name]] != null ? isc._obsPrefix + isc.__remap[name] : isc.__remap[name]); destination[finalObfName] = method; } } //} else { // alert("skipped identical assignment in slot: " + finalName + " of " + method); } } return destination;});// Function naming// ---------------------------------------------------------------------------------------//>DEBUG _nameMethod: labels a function with a name for debug purposes.isc._allFuncs = []isc._allFuncs._maxIndex = 0;isc._funcClasses = new Array(5000);isc._nameMethod = function (method, name, destination) { if (typeof method != isc._$function) return; // if not being added to a class, just use the property name as the function name if (destination.Class == null) return method._name = name; // destination is either: // - a class Object (eg isc.ListGrid) // - an instancePrototype (isc.ListGrid._instancePrototype) // - an instance // - a handful of other objects on which we've added the Class property, including isc.isA, // ClassFactory, and native prototypes (eg window.Array) // only for instance prototypes and class objects, not for instances if (isc.isA != null && isc.isAn.InstancePrototype != null && (isc.isAn.InstancePrototype(destination) || isc.isA.ClassObject(destination))) { var allFuncs = isc._allFuncs; // NOTE: functions installed twice, eg interface methods, will appear twice with // different classnames, but the first entry will be the one used, so interface methods // retain the interface name even when added to other classes. allFuncs[allFuncs._maxIndex] = method; isc._funcClasses[allFuncs._maxIndex] = destination.Class; allFuncs._maxIndex++; return; } // debug: capture all non-Class/Instance methods (eg isA, String extensions, ClassFactory // and other bootstrap) //if (isc._otherFuncs == null) isc._otherFuncs = []; //isc._otherFuncs[isc._otherFuncs.length] = method; // special case isA because isA.Class is a method which detects class objects! // We need to use a property other than Class for the className. var className = (destination == isc.isA ? "isA" : destination.Class); method._className = className; if (isc[destination.Class] == null) method._name = name;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -