[Pas2js] missing definitions

Michael Van Canneyt michael at freepascal.org
Thu Aug 29 13:37:10 CEST 2019



What is the point of this definition ?

You can perfectly do this with the existing TJSArrayMapCallBack. JSValue is
a string.

uses js;

var
   nameLengths: JSValue;
   JavaTpoint: array of JSValue;

begin
   JavaTpoint := ['JavaTpoint','C','C++','RDBMS'];
   nameLengths := TJSArray(JavaTpoint).map(
              function (element: JSValue; index: NativeInt; anArray : TJSArray) : JSValue
               begin
                 asm
                   console.log(typeof(element));
                 end;
                 Result := Length(String(element));  //
              end);
   writeln(nameLengths); 
end.
outputs

home:~/pas2js/packages/rtl> nodejs ta.js
string
string
string
string
10,1,3,5


Michael.

On Thu, 29 Aug 2019, warleyalex via Pas2js wrote:

> TJSArrayMapEventArray = reference to function (element : TJSValueDynArray;
> index: NativeInt; anArray : TJSArray) : JSValue;
>
> Function map(const aCallBack : TJSArrayMapEventArray) : JSValue; overload;
>
>
> -----------------------------------
> {test case}
> var
>  nameLengths: JSValue;
>  JavaTpoint: array of JSValue;
> begin
>
> JavaTpoint := ['JavaTpoint','C','C++','RDBMS'];
>
> nameLengths := TJSArray(JavaTpoint).map(
>             function (element: {JSValue}TJSValueDynArray; index: NativeInt;
> anArray : TJSArray) : JSValue
>              begin
>                Result := TJSArray(element).length;  //
>             end);
>
> nameLengths;   // expected output:  [10, 1, 3, 5]
> -----------------------------------
>
>
>
> --
> Sent from: http://pas2js.38893.n8.nabble.com/
> _______________________________________________
> Pas2js maillist  -  Pas2js at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js


More information about the Pas2js mailing list