[Pas2js] Question regarding the New() function (#34736)
Mattias Gaertner
nc-gaertnma at netcologne.de
Thu Dec 20 17:08:33 CET 2018
On Thu, 20 Dec 2018 16:53:02 +0100 (CET)
Michael Van Canneyt <michael at freepascal.org> wrote:
> 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.
Note: To avoid the array brackets and name conflicts, it could be
defined like this:
function new(Name:string; value:jsvalue): TJSObject; varargs; overload;
> 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.
Are you speaking of the "external name '{}'"?
The direct {} notation requires compiler magic.
Mattias
More information about the Pas2js
mailing list