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

📄 array.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 3 页
字号:
/*
 * 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
 */
 //>	@object	Array// Generic extensions to JavaScript Arrays.  You can call these on any Array.// <P>// JavaScript's native Array is retrofitted to support the <code>List</code> API.//// @implements List// @see List// @treeLocation Client Reference/System// @visibility external//<// Internal notes: Array vs the List interface// - List is an interface which the native JavaScript Array object is retrofitted to implement// - When a given method can be implemented solely in terms of other parts of the List interface,//   there is the possibility that Array and the List interface can share the actual JavaScript//   function object.  When this is done, the method is first defined on Array (for load order//   reasons).// - on Array, several methods can be faster if they use various native functions (like splice()),//   and so a unique implementation appears here// - on List, in order to allow a valid List implementation with a minimum of effort, all methods//   boil down to very simple primitives like addAt// - public documentation for the List interface is in List.js//> @groupDef dataChanged// Operations that change the Array// @title Data Changes//<//> @groupDef iteration// Operations on entire Arrays at once// @title Iteration//<//> @groupDef arrayMath// Math operations on entire Arrays at once// @title Array Math//<// add a "Class" property to the array prototype//	so we can recognize Array instancesArray.prototype.Class = "Array";//>	@classMethod		Array.newInstance()//		Create a new array, adding any arguments passed in as properties.//		Here so we can make standard newInstance() calls on arrays.////		@param	[all arguments]	(object)	objects with properties to override from default//		@return	(array)	new array.//<Array.newInstance = function () {	var instance = [];	isc.addPropertyList(instance, arguments);	return instance;}Array.create = Array.newInstance;//> @classAttr Array.LOADING (String : "loading" : A)// Marker value returned by Lists that manage remote datasets, indicating the requested data is// being loaded.// @visibility external//<Array.LOADING = "loading";Array.isLoading = function (row) {        return row != null && !isc.isAn.XMLNode(row) && row == Array.LOADING;}// add a bunch of methods to the Array prototype so all arrays can use themisc.addMethods(Array.prototype, {//>	@method		array.getPrototype()//		Return the Array.prototype -- for conformity with the Class.getPrototype() method//		Used in exporting arrays.//<getPrototype : function () {	return Array.prototype;},//>	@method		array.newInstance()//		Create a new array, adding any arguments passed in as properties.//		Here so we can make standard newInstance() calls on arrays.////		@param	[all arguments]	(object)	objects with properties to override from default//		@return	(array)	new array.//<newInstance : Array.newInstance,create : Array.newInstance,// List Interface// --------------------------------------------------------------------------------------------//>	@method		array.get()// @include list.get()//<get : function (pos) {	return this[pos]},//>	@method		array.getLength()// @include list.getLength()//<getLength : function () {	return this.length},//>	@method		array.isEmpty()// @include list.isEmpty()//<// NOTE: implementation stolen by List interface.  Must use only List API for internal access.isEmpty : function () {	return this.getLength() == 0;},//>	@method		array.first()// @include list.first()//<first : function () {	return this[0]},//>	@method		array.last()// @include list.last()//<last : function () {	return this[this.length-1]},//>	@method		array.indexOf()// @include list.indexOf()//<indexOf : function (obj, pos, endPos) {	// normalize position to the start of the list	if (pos == null) pos = 0;    if (endPos == null) endPos = this.length - 1;		for (var i = pos; i <= endPos; i++)		if (this[i] == obj) return i;	// not found -- return the not found flag	return -1;}, //>	@method		array.lastIndexOf()// @include list.lastIndexOf()//<lastIndexOf : function (obj, pos, endPos) {	// normalize position to the end of the list	if (pos == null) pos = this.length-1;    if (endPos == null) endPos = 0;		for (var i = pos; i >= endPos; i--)		if (this[i] == obj) return i;	// not found -- return the not found flag    return -1;},//>	@method		array.contains()// @include list.contains()//<// NOTE: implementation stolen by List interface.  Must use only List API for internal access.contains : function (obj, pos) {	return (this.indexOf(obj, pos) != -1);}, //> @method     array.containsAll()// @include list.containsAll()//<// NOTE: implementation stolen by List interface.  Must use only List API for internal access.containsAll : function (list) {    if (list == null) return true;    var length = list.getLength();    for (var i = 0; i < length; i++) {        if (!this.contains(list.get(i))) return false;    }    return true;},//>	@method		array.intersect()// @include list.intersect()//<// NOTE: implementation stolen by List interface.  Must use only List API for internal access.intersect : function () {	var results = [];	// for each element in this array	for (var i = 0; i < this.length; i++) {		// if the element is in each argument, add it to the results		var item = this.get(i),			isPresent = true;		// skip null elements		if (item == null) continue;		// for each array passed in		for (var a = 0; a < arguments.length; a++) {			// if the item is not in that array			if (!arguments[a].contains(item)) {				// it hasn't been found				isPresent = false;				break;			}		}		if (isPresent) results.add(item);	}	// return true	return results;},//>	@method		array.equals()// @include list.equals()//<// NOTE: implementation stolen by List interface.  Must use only List API for internal access.equals : function (list) {    if (list == null || !isc.isA.List(list)) return false;        var length = list.getLength();    // arrays of differing lengths cannot be equals    if (length != this.getLength()) return false;    for (var i = 0; i < length; i++) {        if (list.get(i) != this.get(i)) return false;    }    return true;},//>	@method		array.getItems()// @include list.getItems()//<// NOTE: implementation stolen by List interface.  Must use only List API for internal access.getItems : function (itemList) {	var outputs = [], length = itemList.getLength();	for (var i = 0; i < length; i++) {		outputs[i] = this.get(itemList.get(i));	}	return outputs;},//>	@method		array.getRange()// @include list.getRange()//<getRange : function (start, end) {    if (end == null) end = this.length - 1;	return this.slice(start, end);},//>	@method		array.duplicate()	(A)// @include list.duplicate()//<duplicate : function () {	return isc._emptyArray.concat(this); // NOTE: concat creates a copy},// getData() from list - no analogous method//>	@method		array.set()	// @include list.set()//<set : function (pos, item) {    this[pos] = item;    this.dataChanged();},//>	@method		array.addAt()// @include list.addAt()//<addAt : function (obj, pos) {    if (pos == null) pos = 0;    // copy items in the original array to their new position; copy backwards from last item to    // item at pos, so that none of the items are overwritten    for (var i = this.length - 1; i >= pos; i--) {        this[i+1] = this[i];    }        // add the new object to the list    this[pos] = obj;    	// call dataChanged in case anyone is observing it	this.dataChanged();    // return the object that was added    return obj;},//>	@method		array.removeAt()// @include list.removeAt()//<removeAt : function (pos) {	// make sure the pos passed in is valid	var length = this.length;	if (pos >= length || pos < 0) return null;	// get the item at that position	var it = this[pos];	// remove the item at that position by sliding other things over it	for(;pos < length-1;pos++)		this[pos] = this[pos+1];	// now update the length	this.length--;		// call dataChanged in case anyone is observing it	this.dataChanged();	return it;}, //>	@method		array.add()// @include list.add()//<add : function (object, secondArg) {    var undefined;    if (secondArg !== undefined) {        // support calling as add(index, object)        return this.addAt(object, secondArg);    }	var pos;	// if the list.sortUnique is true, we're only supposed to have each item once	if (this.sortUnique) {		// find the current position of the item in the list		pos = this.indexOf(object);		// if it wasn't found, put it at the end		if (pos == -1) pos = this.length;	} else {		// otherwise we always put the item at the end		pos = this.length;	}	// actually stick the object in the list	this[pos] = object;	// if we are currently sorted, maintain current sort	if (this.sortProps && this.sortProps.length > 0) {        		this.sortByProperties(this.sortProps, this.sortDirections, this.sortNormalizers);	}	// call dataChanged in case anyone is observing it	this.dataChanged();		// return the object that was added	return object;},//>	@method		array.addList()// @include list.addList()//<// NOTE: implementation stolen by List interface.  Must use only List API for internal access.addList : function (list, listStartRow, listEndRow) {    if (list == null) return null;	this._startChangingData();		if (listStartRow == null) listStartRow = 0;	if (listEndRow == null) listEndRow = list.getLength();	for (var pos = listStartRow; pos < listEndRow; pos++) {		this.add(list.get(pos));	}	this._doneChangingData();	// return the objects that were added	return list;},//>	@method		array.setLength()// @include list.setLength()//<setLength : function (length) {	this.length = length;},//>	@method		array.addListAt()// @include list.addListAt()//<addListAt : function (list, pos) {    if (list == null) return null;        // copy items in the original array to their new position; copy backwards from last item to    // item at pos, so that none of the items are overwritten

⌨️ 快捷键说明

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