[Pas2js] Anonymous functions

silvioprog silvioprog at gmail.com
Wed Dec 12 14:29:09 CET 2018


Awesome news!

This feature is amazing and will reduce a lot of code in my projects.

Thank you very much for implementing it!

On Wed, Dec 12, 2018 at 9:43 AM Mattias Gaertner via Pas2js <
pas2js at lists.freepascal.org> wrote:

> Hi,
>
> I implemented anonymous functions in trunk pas2js. Now I need some
> testers.
>
> Delphi calls them "anonymous methods":
>
> http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/anonymousmethods_xml.html
>
> IMO "method" in Pascal usually refer to functions of objects,
> so I think "anonymous functions" is the better name.
>
> type
>   TRefProc = reference to procedure;
>   TProc = procedure;
> procedure DoIt(arg: TRefProc);
> var
>   ref: TRefProc;
>   proc: TProc;
> begin
>   ref:=procedure begin end; // assign
>   ref:=procedure  // note the omitted semicolon
>     var i: integer; // var, types, const, local procedures
>     begin
>     end;
>   DoIt(procedure begin end); // pass as argument
>   refproc:=procedure assembler asm // embed JavaScript
>       console.log("foo");
>     end;
>   // Note that typecasting to non "reference to" does not make
>   // a difference because in JS all functions are closures:
>   proc:=TProc(procedure begin end);
> end;
>
> Note to Lazarus users: you need trunk Lazarus, as codetools in Lazarus
> 2.0 and below do not support anonymous functions.
>
> Mattias


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


More information about the Pas2js mailing list