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

silvioprog silvioprog at gmail.com
Thu Dec 20 16:19:29 CET 2018


Hi.

After #34736 was closed, unfortunately Mantis doesn't allow to comment, so
I decided to ask here. (I don't like Mantis 😑)

What do you think about this syntax sugar?

uses JS;

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

It is productive for me, instead of declaring a lot of local variable or or
literal strings just to create a simple JSON which I could do in a single
line, like:

newObject('foo', 'bar','object', newObject('abc', 123),'array',
newArray(1,2,3))

So, how to use the New() function to develop the newObject() following the
suggested syntax? For example, it doesn't compile:

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

the same to:

Function newObject: TJSObject; varargs; external name 'New';
..
begin
  o := newObject(
    'foo', 'bar',
    'object', newObject('abc', 123),
    'array', newArray(1,2,3)
  );

best,

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


More information about the Pas2js mailing list