<div dir="ltr">Awesome news!<div><br></div><div>This feature is amazing and will reduce a lot of code in my projects.<br><div><br></div><div>Thank you very much for implementing it!</div><div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 12, 2018 at 9:43 AM Mattias Gaertner via Pas2js <<a href="mailto:pas2js@lists.freepascal.org">pas2js@lists.freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I implemented anonymous functions in trunk pas2js. Now I need some<br>
testers.<br>
<br>
Delphi calls them "anonymous methods":<br>
<a href="http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/anonymousmethods_xml.html" rel="noreferrer" target="_blank">http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/anonymousmethods_xml.html</a><br>
<br>
IMO "method" in Pascal usually refer to functions of objects,<br>
so I think "anonymous functions" is the better name.<br>
<br>
type<br>
TRefProc = reference to procedure;<br>
TProc = procedure;<br>
procedure DoIt(arg: TRefProc);<br>
var <br>
ref: TRefProc;<br>
proc: TProc;<br>
begin<br>
ref:=procedure begin end; // assign<br>
ref:=procedure // note the omitted semicolon<br>
var i: integer; // var, types, const, local procedures<br>
begin<br>
end; <br>
DoIt(procedure begin end); // pass as argument<br>
refproc:=procedure assembler asm // embed JavaScript<br>
console.log("foo");<br>
end; <br>
// Note that typecasting to non "reference to" does not make <br>
// a difference because in JS all functions are closures:<br>
proc:=TProc(procedure begin end);<br>
end;<br>
<br>
Note to Lazarus users: you need trunk Lazarus, as codetools in Lazarus<br>
2.0 and below do not support anonymous functions.<br>
<br>
Mattias</blockquote></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Silvio Clécio</div></div></div></div></div></div>