[Pas2js] Question regarding the New() function (#34736)

Michael Van Canneyt michael at freepascal.org
Thu Dec 20 16:53:02 CET 2018



On Thu, 20 Dec 2018, silvioprog wrote:

> On Thu, Dec 20, 2018 at 12:26 PM Michael Van Canneyt <michael at freepascal.org>
> wrote:
>
>> That should be
>>
>> o := new([
>>      'foo', 'bar',
>>      'object', new(['abc', 123]),
>>      'array', TJSArray.new(1,2,3)
>>    ]);
>
>
> Using this:
>
>  o := new([
>    'foo', 'bar',
>    'object', new(['abc', 123]),
>    'array', TJSArray.new(1,2,3)
>  ]);
>
> will generate this:
>
> $mod.o =
> pas.JS.new$1(["foo","bar","object",pas.JS.new$1(["abc",123]),"array",new
> Array(1,2,3)]);

Yes, it is a function call.

>
> Any change to upgrade the transpiler to use this:
>
>  o := new(
>    'foo', 'bar',
>    'object', new('abc', 123),
>    'array', TJSArray.new(1,2,3)
>  );
>
> to generate this?:
>
> $mod.o = {"foo":"bar","object":{"abc",123},"array":new Array(1,2,3)};

Not in the near future. As I explained in my answer to your bugreport: 
The function does checking of the argument types.

I don't want too much "tricks" in the compiler. If later we can think of a
way to do this in a good pascal-ish manner, we'll of course do it.

Michael.


More information about the Pas2js mailing list