[Pas2js] freak implementation of Anonymous methods

warleyalex warleyalex at yahoo.com.br
Tue Jun 19 01:28:37 CEST 2018


trying to mimic anonymous method using non-pascal dialect...

---------------
function beginMethod: JSValue; external name 'function(){//';
function endMethod: JSValue; external name '}//';

type
  TProc = reference to procedure of object;

procedure MyCallback(const aMethod: TJSTimerCallback; const aDelay:
NativeUInt);
begin
   window.setTimeout(aMethod, aDelay);
end;

var
  method1, method2: JSValue;
  myAnonymousMethod: TProc; { Declaration of an anonymous method reference }
begin
// code here

  method1 :=
  beginMethod;
    console.log('Hi');
  endMethod;

  MyCallback(TProcedure(method1), 3000);

  myAnonymousMethod :=   { Assignment of an anonymous method to a reference
}
      TProc(beginMethod);
        writeln('This was written from an anonymous method');
      endMethod;

  myAnonymousMethod;  { Invocation of an anonymous method through its
reference }  

end;
----------------------------------

    $mod.method1 = function(){//();
    window.console.log("Hi");
    }//();
    $mod.method2 = function(){//();
    window.console.log("there");
    }//();
    $mod.w3_Callback($mod.method1,3000);
    $mod.myAnonymousMethod = function(){//;
    pas.System.Writeln("This was written from an anonymous method");
    }//();
    $mod.myAnonymousMethod();




--
Sent from: http://pas2js.38893.n8.nabble.com/


More information about the Pas2js mailing list