Menu

#25 TypedArray :: Constructor

0.1a
closed
7
2005-02-03
2005-02-02
eRom
No

Hi,

The TypedArray class extends Array class. Ok
But when we make a new instance of TypedArray class, we
cant' pass variable directly in constructor.
Look this small exemple :
var ba:Array = new Array(10,20,30);
trace(ba) //return 10,20,30

var ta:TypedArray = new TypedArray(Number, 10,20,30);
trace(ta); //return noting, array is empty.

I think giving possibility to construct a TypedArray
like another basic Array can be very very useful ;)

So I test a small implementation for the new TypedArray
constructor :
----------------------------------------
public function TypedArray(type:Function) {
this.type = type;
var args:Array = arguments.slice(1);
var l:Number = args.length;
for(var i:Number = 0; i < l; i++) validate(args[i]);
splice.apply(this, [0, 0].concat(args));
}
----------------------------------------
I made some tests or everything seems to work well ;)
Morever we validate all objects passed in arguments
chain, so the "strong typing" array is preserved.

Please check the RFE 1114626, concerning the
"getType()" method in TypedClass...

Thanks a lot.
eRom

Discussion

  • eRom

    eRom - 2005-02-02
    • milestone: --> 0.1a
    • priority: 5 --> 7
     
  • Simon Wacker

    Simon Wacker - 2005-02-03

    Logged In: YES
    user_id=922171

    I added support for this feature. The usage is: new
    TypedArray(Number, 10, 20, 30). Type safety is also preserved!

     
  • Simon Wacker

    Simon Wacker - 2005-02-03
    • status: open --> closed
     
  • eRom

    eRom - 2005-02-03

    Logged In: YES
    user_id=1196309

    Thanks a lot ;)

    Bye.
    eRom

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.