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

📄 prototype.js

📁 用来在地图上做操作GIS,在地图上做标记
💻 JS
📖 第 1 页 / 共 5 页
字号:
 * @param {Function} [iterator]	Iterator function to call. Takes the arguments elementValue, and elementIndex, respectively. * @return {Array} Returns an array of the elements with a match to the RegExp. If you specify an iterator, returns the result of calling the iterator on the match. */  grep: function(pattern, iterator) {    var results = [];    this.each(function(value, index) {      var stringValue = value.toString();      if (stringValue.match(pattern))        results.push((iterator || Prototype.K)(value, index));    })    return results;  }, /** * Searches the list of elements for the specified object. * @alias Enumerable.include * @param {Object} object	Object to search for. * @return {Boolean} Returns true if the list of elements contains the object. */  include: function(object) {    var found = false;    this.each(function(value) {      if (value == object) {        found = true;        throw $break;      }    });    return found;  },  /**   * Groups items in fixed-size chunks, using a specific value to fill up the last chunk if necessary.   * @alias Enumerable.inGroupsOf   * @param {Number} number	Number in each group   * @param {Object} fillWith	Value to fill with   * @return {Object} Returns formatted data.   */  inGroupsOf: function(number, fillWith) {    fillWith = fillWith === undefined ? null : fillWith;    return this.eachSlice(number, function(slice) {      while(slice.length < number) slice.push(fillWith);      return slice;    });  }, /** * Calls an iterator function on the elements in a list and accumulates their values into a single value. * @alias Enumerable.inject * @param {Object} memo	Initial value for the iterator. * @param {Function} iterator	Iterator function to call. Takes the arguments elementValue, and elementIndex, respectively. * @return {Object} Returns the final accumulated result. */  inject: function(memo, iterator) {    this.each(function(value, index) {      memo = iterator(memo, value, index);    });    return memo;  }, /** * Calls the specified method on each element in a list and returns an array of the results. * @alias Enumerable.invoke * @param {Function} method	Method to call. * @return {Array} Returns an array of the results. */  invoke: function(method) {    var args = $A(arguments).slice(1);    return this.map(function(value) {      return value[method].apply(value, args);    });  }, /** * Returns the element in the list with the greatest value. If you specify an iterator, calls the iterator function and returns the result with the greatest value. * @alias Enumerable.max * @param {Function} [iterator]	Iterator function to call. Takes the arguments elementValue, and elementIndex, respectively. * @return {Object} Returns the element in the list with the greatest value. If you specify an iterator, calls the iterator function and returns the result with the greatest value. */  max: function(iterator) {    var result;    this.each(function(value, index) {      value = (iterator || Prototype.K)(value, index);      if (result == undefined || value >= result)        result = value;    });    return result;  }, /** * Returns the element in the list with the smallest value. If you specify an iterator, calls the iterator function and returns the result with the smallest value. * @alias Enumerable.min * @param {Function} [iterator]	Iterator function to call. Takes the arguments elementValue, and elementIndex, respectively. * @return {Object} Returns the element in the list with the smallest value. If you specify an iterator, calls the iterator function and returns the result with the smallest value. */  min: function(iterator) {    var result;    this.each(function(value, index) {      value = (iterator || Prototype.K)(value, index);      if (result == undefined || value < result)        result = value;    });    return result;  }, /** * Partitions a list of elements into true elements or values and not-true elements or values. * @alias Enumerable.partition * @param {Object} [iterator]	Iterator function to call. Takes the arguments elementValue, and elementIndex, respectively. * @return {Array} Returns an array of two elements--both of which are arrays. The first array contains all true elements or values (if you specify an iterator) and the second array contains not-true elements or values. */  partition: function(iterator) {    var trues = [], falses = [];    this.each(function(value, index) {      ((iterator || Prototype.K)(value, index) ?        trues : falses).push(value);    });    return [trues, falses];  }, /** * Retrieves the value for the specified property for each element in an array. * @alias Enumerable.pluck * @param {String} property	Name of the property to get. * @return {Array} Returns an array of the property values. */  pluck: function(property) {    var results = [];    this.each(function(value, index) {      results.push(value[property]);    });    return results;  }, /** * Calls an iterator function on the elements in a list and returns all of the elements that cause the iterator to return false. * @alias Enumerable.reject * @param {Function} iterator	Iterator function to call. Takes the arguments elementValue, and elementIndex, respectively. * @return {Array} Returns the elements that the cause the iterator to return false. */  reject: function(iterator) {    var results = [];    this.each(function(value, index) {      if (!iterator(value, index))        results.push(value);    });    return results;  }, /** * Sorts the elements in a list by their iterator results. * @alias Enumerable.sortBy * @param {Object} iterator	Iterator function to call. Takes the arguments elementValue, and elementIndex, respectively. * @return {Array} Returns an array of elements sorted by their iterator results. */  sortBy: function(iterator) {    return this.map(function(value, index) {      return {value: value, criteria: iterator(value, index)};    }).sort(function(left, right) {      var a = left.criteria, b = right.criteria;      return a < b ? -1 : a > b ? 1 : 0;    }).pluck('value');  }, /** * Creates an array of the elements in a list. * @alias Enumerable.toArray * @return {Array} Returns an Array of elements in the list. */  toArray: function() {    return this.map();  }, /** * Merges elements from one or more lists into a single list. * @alias Enumerable.zip() * @param {Array} ... One or more lists of elements to merge. * @return {Array} Returns a single array. */  zip: function() {    var iterator = Prototype.K, args = $A(arguments);    if (typeof args.last() == 'function')      iterator = args.pop();    var collections = [this].concat(args).map($A);    return this.map(function(value, index) {      return iterator(collections.pluck(index));    });  },  /**   * Returns the size of the enumeration.   * @alias Enumerable.size   * @return {Number} Returns the size of the enumeration.   */  size: function() {    return this.toArray().length;  }, /** * Returns a human-readable string version of the list of elements. * @alias Enumerable.inspect * @return {String} Returns a human-readable string version of the list of elements. */  inspect: function() {    return '#<Enumerable:' + this.toArray().inspect() + '>';  }}Object.extend(Enumerable, {  map:     Enumerable.collect,  find:    Enumerable.detect,  select:  Enumerable.findAll,  member:  Enumerable.include,  entries: Enumerable.toArray});/** * Converts the argument "iterable" into an Array object. * @alias $A * @param {Object} iterable	Object to be converted to an Array. * @return {Array} Returns an Array. */var $A = Array.from = function(iterable) {  if (!iterable) return [];  if (iterable.toArray) {    return iterable.toArray();  } else {    var results = [];    for (var i = 0, length = iterable.length; i < length; i++)      results.push(iterable[i]);    return results;  }}if (Prototype.Browser.WebKit) {  $A = Array.from = function(iterable) {    if (!iterable) return [];    if (!(typeof iterable == 'function' && iterable == '[object NodeList]') &&      iterable.toArray) {      return iterable.toArray();    } else {      var results = [];      for (var i = 0, length = iterable.length; i < length; i++)        results.push(iterable[i]);      return results;    }  }}Object.extend(Array.prototype, Enumerable);if (!Array.prototype._reverse)  Array.prototype._reverse = Array.prototype.reverse;Object.extend(Array.prototype, {  _each: function(iterator) {    for (var i = 0, length = this.length; i < length; i++)      iterator(this[i]);  }, /** * Clears an array of all content. * @alias Array.clear * @return {Array} Returns an empty array. * @extends {Array} */  clear: function() {    this.length = 0;    return this;  }, /** * Returns the first element of an array. * @alias Array.first * @return {Object, String, Number} Returns the first element of an array. * @extends {Array} */  first: function() {    return this[0];  }, /** * Returns the last element of an array. * @alias Array.last * @return {Object, String, Number} Returns the last element of an array. * @extends {Array} */  last: function() {    return this[this.length - 1];  },  /**   * Returns a new version of the array, without any null/undefined values.   * @alias Array.compact   * @return {Array}	Returns a new version of the array, without any null/undefined values.   * @extends {Array}   */  compact: function() {    return this.select(function(value) {      return value != null;    });  }, /** * Flattens an array containing elements that are arrays into a single array. * @alias Array.flatten * @return {Array} Returns a one-dimensional array. * @extends {Array} */  flatten: function() {    return this.inject([], function(array, value) {      return array.concat(value && value.constructor == Array ?        value.flatten() : [value]);    });  },  /**  * Returns an array without the specified elements.  * @alias Array.without  * @param {Array, String, Number} ... One or more elements to exclude from the array.  * @return {Array} Returns an array without the specified elements.  * @extends {Array}  */  without: function() {    var values = $A(arguments);    return this.select(function(value) {      return !values.include(value);    });  },  /**  * Gets the zero-based index position of the specified element in an array.  * @alias Array.indexOf  * @param {Object} object	Element to get the index position of.  * @return {Number} Returns the index position of the element.  * @extends {Array}  */  indexOf: function(object) {    for (var i = 0, length = this.length; i < length; i++)      if (this[i] == object) return i;    return -1;  },  /**  * Reverses the order of elements in an array.  * @alias Array.reverse  * @param {Boolean} inline	If true, indicates that the array itself should be reversed, instead of just creating a copy. Default is true.  * @return {Array} Returns an array with the order of its elements reversed.  * @extends {Array}  */  reverse: function(inline) {    return (inline !== false ? this : this.toArray())._reverse();  },  /**   * Reduces arrays: one-element arrays are turned into their unique element, while multiple-element arrays are returned untouched.   * @alias Array.reduce   * @return {Array} Returns the reduced array.   * @extends {Array}   */  reduce: function() {    return this.length > 1 ? this : this[0];  },  /**   * Produces a duplicate-free version of an array. If no duplicates are found, the original array is returned.   * @alias Array.uniq   * @param {Object} sorted   * @return {Array} Produces a duplicate-free version of an array. If no duplicates are found, the original array is returned.   * @extends {Array}   */  uniq: function(sorted) {    return this.inject([], function(array, value, index) {      if (0 == index || (sorted ? array.last() != value : !array.include(value)))        array.push(value);      return array;    });  },  /**   * Returns a duplicate of the array, leaving the original array intact.   * @alias Array.clone   * @return {Array} Returns a duplicate of the array, leaving the original array intact.   * @extends {Array}   */  clone: function() {    return [].concat(this);  },  /**   * Returns the size of the array.   * @alias Array.size   * @return {Array} Returns the size of the array.   * @extends {Array}   */  size: function() {    return this.length;  },  /**  * Formats an array into a human-readable string.  * @alias Array.inspect  * @return {String} Returns a string version of the array.  * @extends {Array}  */  inspect: function() {    return '[' + this.map(Object.inspect).join(', ') + ']';  },  /**   * Returns a JSON string.   * @alias Array.toJSON   * @return {Array}	Returns a JSON string.   * @extends {Array}   */  toJSON: function() {    var results = [];    this.each(function(object) {      var value = Object.toJSON(object);      if (value !== undefined) results.push(value);    });    return '[' + results.join(', ') + ']';  }

⌨️ 快捷键说明

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