[Pas2js] @pointer/reference inside ASM block - missing feature
Michael Van Canneyt
michael at freepascal.org
Sun Jun 10 16:27:11 CEST 2018
On Sat, 9 Jun 2018, warleyalex via Pas2js wrote:
> Michael Van Canneyt wrote
>> Why do you need @ ?
>
> //----VERSION 1 # compile but does not work
> -------------------------------------------
> P1 := TPerson.new;
> P1.Name:= 'John';
> P1.Age:= 52;
> P1.Status:= true;
>
> function Myfunction(const aValue: String): String;
> begin
> console.log(aValue);
> result := aValue;
> end;
>
> {...}
> begin
> // code here
> asm
> window.Myfunction1 = Myfunction(P1.Name); // -->Uncaught
> ReferenceError: Myfunction is not defined
> end;
>
> end;
> //---------------------------------------------------------------------------------------------
> The pas2js compiler does neither parse, nor check the syntax of the JS;
> smart linking did omit the Myfunction1 method, and I've got the "Uncaught
> ReferenceError: Myfunction is not defined"
You cannot just use the Myfunction name from Javascript.
It's probably more something like $mod.Myfunction
See e.g.
https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/utils/pas2js/docs/translation.html?view=co#asm
> //------- VERSION 3 # using @prefix suggestion
> -------------------------------
> {...}
> begin
> // code here
> asm
> window.Myfunction1 = @Myfunction(P1.Name); // --> should work as well
> end;
>
> end;
>
> //----------------------------------------------------------------------------
> In Version 3, pas2js compiler quickly figure out that is an Object Pascal
> variable, understands the @ character and it will initialize/auto include
> the Myfunction for us. :)
Maybe one day it should just recognize
asm
window.Myfunction1 = Myfunction(P1.Name); // --> should work as well
end;
There is no need for the @ sign.
Michael.
More information about the Pas2js
mailing list