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

📄 object.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 3 页
字号:
          if (isc.isA != null && isc.isAn.Instance != null && isc.isAn.Instance(destination) &&        !isc.isAn.InstancePrototype(destination))     {        // instance methods need to be labelled with their name since we don't want to store a        // list of instance IDs for function name lookups (it would grow indefinitely)        method._name = name;        // this method is an instance-specific override (using an instance as an anonymous        // class).  Mark it as such.        method._instanceSpecific = true;        // if there's already a method on the destination with the same name,        // this is also an override (as opposed to just a method that was added)        if (destination[name] != null) method._isOverride = true;    }    // XXX Note: we could use a check like the following to detect and label class    // methods vs instance methods    // if (ClassFactroy.getClass(destination.Class) === destination) {}//<DEBUG   // ---------------------------------------------------------------------------------------//>	@classMethod isc.getKeys()////	Return all keys (property names) of a given object////	@param	object			(object)	object to get properties from//	@return					(Array) String names of all properties.  NOTE: never null// @visibility external//<isc.addGlobal("getKeys", function (object) {	var list = [];	if (object != null) {		for (var key in object) {			list[list.length] = key;		}	}	return list;});//>	@classMethod isc.getValues()////	Return all values of a given object////	@param	object			(object) object to get properties from//	@return					(Array) values of all properties.  NOTE: never null// @visibility external//<isc.addGlobal("getValues", function (object) {	var list = [];	if (object != null) {		for (var key in object) {			list[list.length] = object[key];		}	}	return list;});//> @classMethod isc.sortObject()// Given a simple javascript object, return that object sorted by keys, such that when iterating// through the properties of the object, they will show up in sorted order.<br>// Usage example - may be used to sort a +link{FormItem.valueMap, formItem valueMap} defined// as an object.// @param object (object) Object to sort// @param [comparitor] (function) Comparitor function to use when sorting the objects keys// @return (object) sorted version of the object passed in.// @visibility external//<isc.addGlobal("sortObject", function (object, sortComparitor) {    if (!isc.isA.Object(object)) return object;    if (isc.isAn.Array(object)) {        if (sortComparitor != null) return object.sort(sortComparitor);        return object.sort();    }    var keys = isc.getKeys(object);    keys = (sortComparitor == null ? keys.sort() : keys.sort(sortComparitor));    var sortedObject = {};    for (var i = 0; i < keys.length; i++) {        sortedObject[keys[i]] = object[keys[i]];    }    return sortedObject});//> @classMethod isc.sortObjectByProperties()// Given a simple javascript object, return that object sorted by properties, such that when // iterating through the properties of the object, values will show up in sorted order.<br>// Usage example - may be used to sort a +link{FormItem.valueMap, formItem valueMap} defined// as an object by display value.// @param object (object) Object to sort// @param [comparitor] (function) Comparitor function to use when sorting the object properties// @return (object) sorted version of the object passed in.// @visibility external//<isc.addGlobal("sortObjectByProperties", function (object, sortComparitor) {    if (!isc.isA.Object(object)) return object;    if (isc.isAn.Array(object)) {        if (sortComparitor != null) return object.sort(sortComparitor);        return object.sort();    }    var values = isc.getValues(object);    values = (sortComparitor == null ? values.sort() : values.sort(sortComparitor));    var sortedObject = {};    for (var i = 0; i < values.length; i++) {        var value = values[i];        for (var key in object) {            if (object[key] === value) {                sortedObject[key] = object[key];                continue;            }        }    }    return sortedObject});//> @classMethod isc.addDefaults()//// Copy any properties that do not already have a value in destination.  Null and zero values// are not overwritten, but 'undef' values will be.//// @param destination (Object) Object to which properties will be added.// @param source (Object) Object from which properties will be added.// @return (Object) The destination object is returned.// @visibility external//< isc.addGlobal("addDefaults", function (destination, source) {    if (destination == null) return;    var undef;    for (var propName in source) {        if (destination[propName] === undef) destination[propName] = source[propName];    }    return destination;});//>	@classMethod isc.propertyDefined()////	Is some property specified on the object passed in?  This will return true if //  <code>object[propertyName]</code> has ever been set to any value, and not deleted.<br>//  May return true even if <code>object[propertyName] === undefined</code> if the property //  is present on the object and has been explicitly set to undefined.////	@param	object			(object)	object to get properties from//	@return					(object[])	values of all properties//  @visibility external//<isc.addGlobal("propertyDefined", function (object, propertyName) {    if (object == null) return false;    var undefined;    if (object[propertyName] !== undefined) return true;        	var properties = isc.getKeys(object);    return (properties.contains(propertyName));});//> @method isc.applyMask()// Create a copy of an Object or Array of Objects that has been trimmed to a specified set of// properties.// <p>// <code>mask</code> is the list of properties to return.  Can be an array of strings or an object.// If an object, the properties returned will be those that are present in the object.  NOTE: this// includes properties that exist because they've been explicitly set to null.// <p>// If no mask is specified, returns a duplicate of the input// If no inputs are specified, returns an empty object.// // @param input   (Object or Array)   object to be masked// @param mask    (Object or Array)   set of properties to limit output to// //<// NOTE: not external because behavior is a little odd:// - returns non-null for null input// - if mask is null and provided an Array, returns an Object instead of a dup'd Array// we need to check out the framework uses of applyMask and makes sure changing the behavior is// OK//// XXX if applyMask with the input as an empty Array, you will get an empty Array as output.// So applyMask cannot be used to filter properties that exist on an Array instance.isc.applyMask = function (input, mask) {	var output = {};	// if no input passed in, return empty output	if (input == null) return output;	// if no mask passed in, return all fields from input	if (mask == null) {		return isc.addProperties(output, input);	}    var inputWasSingle = false;	if (!isc.isAn.Array(input)) {        inputWasSingle = true;        input = [input];    }    // convert the mask to an Array of property names if it's an object    if (!isc.isAn.Array(mask)) mask = isc.getKeys(mask);    var output = [],        inputObj, outputObj,        key, undef;    for (var i = 0; i < input.length; i++) {        inputObj = input[i];        outputObj = output[i] = {};        // return only the specified properties        for (var j = 0; j < mask.length; j++) {            key = mask[j];            if (inputObj[key] === undef) continue;            outputObj[key] = inputObj[key];        }    }    return (inputWasSingle ? output[0] : output);}isc._digits = {};isc._floor = Math.floor;isc._$minus = "-";for (isc._iterator = 0; isc._iterator < 10; isc._iterator++)     isc._digits[isc._iterator] = isc._iterator.toString();    isc._fillNumber = function (template, number, startSlot, numSlots) {            var lastSlot = startSlot + numSlots - 1,        origNumber = number,        didntFit = false,        negative;    if (number < 0) {        negative = true;        number = -number;        template[startSlot] = this._$minus;        startSlot += 1;        numSlots -= 1;    }        while (number > 9) {        // reduce by 10x, round off last digit and subtract to find what it was        var newNumber = this._floor(number/10),            lastDigit = number - (newNumber*10);        // fill slots last first        template[lastSlot] = this._digits[lastDigit];        number = newNumber;                if (lastSlot == (startSlot+1) && number > 9) {            // number to large for allocated number of slots            isc.Log.logWarn("fillNumber: number too large: " + origNumber +                            isc.Log.getStackTrace());            didntFit = true;            break;        }        lastSlot -= 1;            }    if (didntFit) {                lastSlot = startSlot + numSlots - 1        template[lastSlot--] = (!negative ? origNumber : -origNumber);    } else {        template[lastSlot--] = this._digits[number];    }        // null out remaining slots    for (var i = lastSlot; i >= startSlot; i--) {        template[i] = null;    }}// try to interpolate different types as a boolean//// returns default if value is undefined or null// returns false if value is//   - the string "false" or "FALSE"//   - the number 0//   - the boolean value false// otherwise returns trueisc.booleanValue = function (value, def) {    // if the value is unset, return the specified default (so,     if (value == null) return def;        if (isc.isA.String(value)) return value != isc._false && value != isc._falseUC;    return value ? true : false;}// isc.objectToLocaleString()// Centralized, customizeable toLocaleString() formatter for objects. isc.iscToLocaleString = function (object) {    if (object != null) {        return object.iscToLocaleString ? object.iscToLocaleString() :                    (object.toLocaleString ? object.toLocaleString() :                        (object.toString ? object.toString() : isc.emptyString + object));    }    return isc.emptyString + object;}

⌨️ 快捷键说明

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