User Guide
248 Working with Arrays
The splice() method takes an arbitrary list of arguments, but the first two arguments always
refer to an index number and the number of elements to delete. This is why the overridden
splice() method does type checking only for args array elements in index positions 2 or
higher. One point of interest in the code is that there appears to be a recursive call to
splice() inside the for loop, but this is not a recursive call because args is of type Array
rather than TypedArray, which means that the call to
args.splice() is a call to the
superclass version of the method. After the
for..in loop concludes, the args array contains
only values of the correct type in index positions 2 or higher, and
splice() calls its own
superclass version, as shown in the following code:
AS3 override function splice(...args):*
{
if (args.length > 2)
{
for (var i:int=2; i< args.length; i++)
{
if (!(args[i] is dataType))
{
args.splice(i,1);
}
}
}
return (super.splice.apply(this, args));
}
The unshift() method, which adds elements to the beginning of an array, also accepts an
arbitrary list of arguments. The overridden
unshift() method uses an algorithm very similar
to that used by the
push() method, as shown in the following example code:
AS3 override function unshift(...args):uint
{
for (var i:* in args)
{
if (!(args[i] is dataType))
{
args.splice(i,1);
}
}
return (super.unshift.apply(this, args));
}
}