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

silvioprog silvioprog at gmail.com
Thu Dec 20 17:02:10 CET 2018


On Thu, Dec 20, 2018 at 12:53 PM Michael Van Canneyt <michael at freepascal.org>
wrote:

> I don't want too much "tricks" in the compiler.


Me too, but ...


> If later we can think of a
> way to do this in a good pascal-ish manner, we'll of course do it.
>

... a pascal-ish manner, should be:

var
  o: TJSObject;
begin
  o := TJSObject.new([
    'foo', 'bar',
    'object', TJSObject.new(['abc', 123]),
    'array', TJSArray.new(1,2,3)
  ]);
  Writeln(TJSJSON.stringify(o));
end.

or:

var
  o: TJSObject;
begin
  o := TJSObject.new(
    'foo', 'bar',
    'object', TJSObject.new('abc', 123),
    'array', TJSArray.new(1,2,3)
  );
  Writeln(TJSJSON.stringify(o));
end.

however, it seems not possible. Anyway, these syntax above are better than
the newObject()/newArray() ones. Another possibility (very verbose, but
...) would:

var
  o: TJSObject;
begin
  o := TJSObject.new(
    TJSPair.new('foo', 'bar',)
    TJSPair.new('object', TJSObject.new('abc', 123)),
    TJSPair.new('array', TJSArray.new(1,2,3))
  );
  Writeln(TJSJSON.stringify(o));
end.

--
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20181220/54e07030/attachment.html>


More information about the Pas2js mailing list