iterator.class.js

来自「《JavaScript王者归来》examples.rar」· JavaScript 代码 · 共 59 行

JS
59
字号
# language: JSVM2

/**
 * @fileoverview js.util.Iterator class {@link http://jsvm.org/}
 * @file		Iterator.jsc
 * @author	Wan Changhua
 * @version	2.01, 10/23/05
 * @since		JSVM1.0
 */

package js.util;


/**
 * Create a new Iterator instance.
 * Inherit from JObject
 * @author	Wan Changhua
 * @version	2.01, 10/23/05
 * @extends JObject
 * @class This is the iterator class.
 * @constructor
 */

class Iterator (aArray) {

	/**
	 * @private
	 */
	var array = aArray;
	var index = 0;

	/**
	 * Returns <tt>true</tt> if the iteration has more elements.
	 * @return  <code>true</code>  if it has next;
	 *          <code>false</code> otherwise.
	 * @type boolean
	 */
	this.hasNext = function() {
		return (array.length > index);
	}
	
	/**
	 * Returns the next element in the iteration.
	 * @return  the next element in the iteration.
	 * @type Object
	 */
	this.next = function() {
		return array[index++];
	}
	
    /**
     * Returns an array containing all of the elements in this iterator
     * @type Array
     */
	this.toArray = function () {
		return array.concat([]);
	}

}

⌨️ 快捷键说明

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