[Pas2js] TJSXMLHttpRequest questions

Ryan Joseph ryan at thealchemistguild.com
Sun May 20 14:16:28 CEST 2018



> On May 20, 2018, at 5:51 PM, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
> 
> There are no anonymous methods yet, but there are closures:
> 
> procedure Test;
> var
>  xhr : TJSXMLHttpRequest;
> 
>  procedure HandleLoaded;
>  begin
>    if (xhr.readyState = 4) or (xhr.status = 200) then
>      writeln(xhr.responseText);
>  end;
> 
> begin
>  xhr := TJSXMLHttpRequest.new;
>  xhr.open('GET', 'file.html');
>  xhr.onreadystatechange := @HandleLoaded;
>  xhr.send;
> end;

I thought closures were what FPC was calling anonymous methods. That’s a pretty important feature for JavaScript.

That means we need to have a global out in the stack for every time we need to use TJSXMLHttpRequest? I guess we could rely on a “controller” class or something to make this manageable (is that even possible to use a class method?). Could subclassing TJSXMLHttpRequest be an option?



Regards,
	Ryan Joseph



More information about the Pas2js mailing list