[Pas2js] Records as pure data?

Mattias Gaertner nc-gaertnma at netcologne.de
Wed May 9 12:56:11 CEST 2018


On Wed, 9 May 2018 16:46:46 +0700
Ryan Joseph <ryan at thealchemistguild.com> wrote:

>[...]
> type
>   TVec2 = data record
>     x, y: single;
>   end;
> 
> // var v = new Array(0, 0);
> v := TVec2.Create;
> 
> // v[0] = 1;
> v.x := 1;
> 
> fields just reference array indexes by name, so x = 0, y = 1 in this example.
> 
> Does that work?

No. JS objects are associative arrays. There is no first or second
property. This is true for arrays as well. In JS v[0] is the same as
v["0"].

If you want a two element Float32Array and access its 0 and 1 element
as x and y, then maybe this could eventually be achieved with a class
helper or an advanced record.

Mattias


More information about the Pas2js mailing list