[Pas2js] My 1st type helper
    Mattias Gaertner 
    nc-gaertnma at netcologne.de
       
    Thu Feb 28 23:25:28 CET 2019
    
    
  
On Wed, 27 Feb 2019 06:07:35 -0700 (MST)
warleyalex via Pas2js <pas2js at lists.freepascal.org> wrote:
> -------------------------------------------
> type
>  TFloatHelper  =  type helper for Float  
>    const NPI = 3.141592;
>    function ToStr: String;
>  end;
> 
> function  TFloatHelper.ToStr: String;
> begin
>   Result:=  FloatToStr(Self);
> end;
> 
> ------------------------
> this syntax
> //  TFloatHelper  =  helper for Float 
> 
> // hum, doesn't work for me, I had to include the keyword type
Correct.
In $mode delphi you can use 'record helper for Float'.
> How to use the float helper function ToStr?
> 
> -----------------------
> var
>   ReturnValue : Float;
> begin
>   ReturnValue := 2.71;
>     console.log(ReturnValue * ReturnValue.NPI);                     
> //8.51371432
> //  console.log((ReturnValue * ReturnValue.NPI).ToStr);
FPC and Delphi do not allow that. I don't know why. pas2js does.
> //8.51371432  does not work for me
> //  console.log((ReturnValue * TFloatHelper.NPI).ToStr);         
Helpers are not full types. They extend types:
(ReturnValue * Float.NPI).ToStr
> //8.51371432 does not work for me
> //  console.log(TFloatHelper.ToStr(ReturnValue *
> Float.NPI));  //8.51371432 does not work for me
Good.
> //  console.log((ReturnValue *
> ReturnValue.NPI).ToStr );        //8.51371432 does not work for me
Isn't that same as above?
Mattias
> 
> 
> 
> 
> --
> Sent from: http://pas2js.38893.n8.nabble.com/
> _______________________________________________
> Pas2js maillist  -  Pas2js at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js
    
    
More information about the Pas2js
mailing list