[Pas2js] Bootstrap & Helper techniques

Michael Van Canneyt michael at freepascal.org
Sun Sep 29 16:20:10 CEST 2019



On Sun, 29 Sep 2019, warleyalex via Pas2js wrote:

> OK. In short, we can achieve (pass on object argument) the same effect with:

Yes.

> begin
>  { Test I - it is possible to pass a parameter "inline" without having to
> declare a variable of that type first,
>     but we don't have the code completion
>  }
>  DoSomething1( New(['MyName','Test1','Price',1, 'Func', @Go]) );

Simple, but not typesafe and error prone. Compiler will not check anything.

>
>  { Test II - inherited from TJSObject to access the constuctor }
>  o := TTOptions.new;

Correct.

>  { Test III - it is not necessary to inherite from TJSObject at all }
>  op := TTableOptions(CreateObject);

I consider this a dirty hack involving a typecast :)

>  { Test IV - using a factory function together with the record }
>  DoSomething4(Options('Test4',4, @Go));

Correct. You could put this in an overloaded constructor.

>  { Test VI - using advanced record approach }
>  DoSomething6( TMyShopItem.Create('Test6', 6, @Go) );

Yes, but note that for a record, all fields will always be present, which is
not always what you want (or what a library expects). 
That was the point I was trying to make in my mail.

Michael.


More information about the Pas2js mailing list