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

silvioprog silvioprog at gmail.com
Thu Dec 20 18:11:27 CET 2018


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

> Yes.
>
> The reason that we need to wait for type helpers is the following:
>
> The feature you request requires code to be generated by the compiler, as
> the standard Javascript object does not contain the calls you suggest.
>

Indeed.


> But the external classes do not contain code.
> In this sense they are comparable to interface definitions.
>
> IMO it would not be good design to allow code in an external class
> definition.
>

I agree, since it avoid the programmer to chance the original behavior of
the imported feature. Class helpers are very welcome here. :-)

So, the code cannot go in the external class definition, but it can go
> in a type helper, which will then look something like this:
>
> TObjectHelper = Class helper for TJSObject
>    constructor new(Values : TJSValueDynArray); varargs; overload;
>    constructor new(Name : String; Value : JSValue); varargs; overload;
>    // ++ Some other real killer functions you can think of...
> end;
>

Plus:

TObjectHelper = Class helper for TJSObject
   constructor new(Values : TJSValueDynArray); varargs; overload;
   constructor new(Name : String; Value : JSValue); varargs; overload;
   constructor new; varargs; overload; // allowing to create empty objects,
like '{}' :-)
  ...
end;

But I have a doubt. If the JS.pas contains the TObjectHelper, will the
programmer be able to create his helpers for TJSObject as well?


> So, maybe you still want to change your vote in the poll ? ;-)
>

Hahaha I'm going to change it. 😀

Thank you for reviewing all the ideas.

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


More information about the Pas2js mailing list