TypedArray
Inherits from:Array
Implements:
- Author: Simon Wacker, Martin Heidegger
- Classpath: org.as2lib.data.holder.array.TypedArray
- File last modified: Sunday, 29 May 2005, 10:29:36
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);
See also:
Constructor
TypedArray
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);
Parameters:
type:
the type of the elements this array expects
.. :
any number of elements to populate this array with
Instance methods
concat
function concat (
) : TypedArray
Concatenates 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.
Parameters:
..:
any number of elements to concatenate the elements of this array with
Returns:
a new array that contains the elements of this array as well as the
passed-in elements
See also:
getType
function getType (
Void) : Function
Returns the type all elements of this array have.
This is the type passed-in on construction.
Returns:
the type all elements of this array have
push
function push (
value) : Number
Adds 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.
Parameters:
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
Returns:
the new length of this array
Throws:
IllegalArgumentException if one of the passed-in elements is of invalid
type
See also:
toString
function toString (
) : String
Returns the string representation of this array.
Returns:
the string representation of this array
Specified by:
unshift
function unshift (
value) : Number
Adds 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.
Parameters:
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
Returns:
the new length of this array
Throws:
IllegalArgumentException if one of the passed-in elements is of invalid
type
See also: