Core Methods
The constructors are core to the class. We need them so that objects can be generated from our class.

  • Static factory constructor method
  • Traditional constructor
  • toString method for user-friendliness
/**
 * Static factory methods that returns new QueryArray using
 * 	the passed fixed array "array"
*/
1
static from(array) { //Call traditional constructor return new this(array); } /** Traditional constructor -- set ivar elements to passed array */
2
constructor(array) { this.elements = array; } /** Returns nice display string */
3
toString() { return this.elements.toString(); }
Test It
Here we run a simple test
class QueryArray {
	// -----------------------------------------------------
	//Instance Variables (Ivars)

	//this.elements -- a fixed array holding the elements

	// -----------------------------------------------------
	//Constructors

	/** Static factory methods that returns new QueryArray using
	the passed fixed array "array" */
	static from(array) {
		//Call traditional constructor
		return new this(array);
	}

	/** Traditional constructor -- set ivar elements to passed array */
	constructor(array) {
		this.elements = array;
	}

	// -----------------------------------------------------
	//Core Instance Methods

	/** Returns nice display string */
	toString() {
		return this.elements.toString();
	}

} _br_ _br_//Test It

//fixed array and query array
var farray, qarray;

//Example data (list of cities)
farray = City.newSampleSet1();

//Construct QueryArray
qarray = QueryArray.from(farray );

//Print It
println(qarray)