BasicInterface
TypedArray acts like a normal array but assures that only objects of a
specific type are added to the array.
Note that elements that are added to this array using the dot-syntax do not
get type-checked. For example:
myArray[0] = "value1";
// or
myArray.myProp = "value2"; // myArray["myProp"] = "value2";
Example:
var array:Array = new TypedArray(Number);
array.push(0);
array.push(1);
array.push(2);
// throws an IllegalArgumentException because the element is not of the expected type
array.push("myString");
You can also construct your array the following way:
var array:Array = new TypedArray(Number, 0, 1, 2);
new TypedArray()public function TypedArray(type:Function)
Constructs a new TypedArray instance.
You can optionally pass-in elements to populate this array with after the type
parameter. These elements also get type-checked. For example:
var array:Array = new TypedArray(Number, 1, 2, 3);
type | the type of the elements this array expects |
... | any number of elements to populate this array with |
public function getType(Void):FunctionReturns the type all elements of this array have.
This is the type passed-in on construction.
the type all elements of this array have
public function concat():TypedArrayConcatenates the elements specified in the parameter list with the elements of this array and returns a new array containing these elements.
This array itself is left unchanged.
The returned array expects elements of the same type as this array does.
If you do not pass-in any elements a duplicate of this array gets returned.
... | any number of elements to concatenate the elements of this array with |
a new array that contains the elements of this array as well as the passed-in elements
concat() in Array
public function push(value):NumberAdds one or more elements to the end of this array and returns the new length of this array.
The passed-in elements get type-checked first. They will only be added if they are all of the correct type.
value | the new element to add to the end of this array |
... | any number of further elements to add to the end of this array |
the new length of this array
| IllegalArgumentException | if one of the passed-in elements is of invalid type |
push() in Array
public function unshift(value):NumberAdds one or more elements to the beginning of this array and returns the new length of this array.
The passed-in values get type-checked first. They will only be added if they are all of the correct type.
value | the new element to add to the beginning of this array |
... | any number of further elements to add to the beginning of this array |
the new length of this array
| IllegalArgumentException | if one of the passed-in elements is of invalid type |
unshift() in Array
public function toString():StringReturns the string representation of this array.
the string representation of this array
toString() in org.as2lib.core.BasicInterface
toString() in Array