Forum > Free Pascal
Pas2JS missing language features ?
dubst3pp4:
--- Quote from: mattias on January 17, 2018, 02:38:57 pm ---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.
--- End quote ---
Wow, good to know! So it seems it is now time to have a deep look into PAS2JS :-) Thanks for the hint!
Edit: found the section in the wiki: http://wiki.freepascal.org/pas2js#Importing_Javascript_classes Sorry for not reading carefully enough!
avra:
I also miss "Type alias" very much. Too bad it's not in the list. I use it a lot.
BeniBela:
Pointers would be nice :)
PascalDragon:
--- Quote from: dubst3pp4 on January 17, 2018, 02:52:40 pm ---@mattias
Can 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:
--- End quote ---
No, this doesn't work in Free Pascal (or at least only by chance), because the value of y is loaded from the stack or a register depending on the calling convention. For this to work closure support is needed (which is already a Work In Progress) as that stores the value of y at a temporary, hidden class instance that is destroyed once the procedure reference moves out of scope again.
PascalDragon:
--- Quote from: mattias on January 17, 2018, 02:23:36 pm ---Note that pas2js supports closures, so for example instead of using an anymous function you can use a sub function:
Delphi:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function MakeAdder(y: Integer): TFuncOfInt;begin Result := function(x: Integer) begin Result := x + y; end;end;
Pas2js:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function MakeAdder(y: Integer): TFuncOfInt; function Adder(x: Integer): integer; begin Result := x + y; end;begin Result:=@Adder;end;
--- End quote ---
Please note that once anonymous functions/closures are supported in FPC I plan to extend it so that local functions/procedures can also be passed to "reference to procedure/function" variables as well. This way those that don't want to use anonymous functions due to their syntax can still enjoy their capabilities.
Navigation
[0] Message Index
[#] Next page
[*] Previous page