Total Members Voted: 40
Voting closed: February 28, 2018, 09:22:09 am
Same in pas2js. It supports external classes, functions and variables. See unit js for examples.You can even descend a new Pascal class from an external JS class.And you can use asm-blocks to insert JS directly. But the external classes are so powerful, that even the RTL hardly use asm blocks.
@mattiasCan I use this also in native Free Pascal code? I've tried your interesting closure example, but in my version the value of y is initialized to the same value as x at every call:
Note that pas2js supports closures, so for example instead of using an anymous function you can use a sub function:Delphi:Code: Pascal [Select][+][-]function MakeAdder(y: Integer): TFuncOfInt;begin Result := function(x: Integer) begin Result := x + y; end;end; Pas2js:Code: Pascal [Select][+][-]function MakeAdder(y: Integer): TFuncOfInt; function Adder(x: Integer): integer; begin Result := x + y; end;begin Result:=@Adder;end;
I just can not just believe, anonymous functions is not at top of the list.It's so boring writing sub functions to do simple things.