[Pas2js] Built-in helper methods for Double type

warleyalex warleyalex at yahoo.com.br
Wed Sep 4 20:26:42 CEST 2019


solution using type helpers:
==================
type
  Float = Double;

type
{ TDoubleHelper }
TDoubleHelper = type helper for Float
   function toFixed(aNumber: Double; fractionDigits: integer): string;
assembler;
end;

{ TDoubleHelper }
function TDoubleHelper.toFixed(aNumber: Double; fractionDigits: integer):
string; assembler;
asm
  return Number(aNumber).toFixed(fractionDigits);
end;


var
  ReturnValue: float;
  x: String;
begin
  x := ReturnValue.toFixed(sin(10.1) * 2.5, 2); 

  rtl.createHelper($mod,"TDoubleHelper",null,function () {
    this.toFixed = function (aNumber, fractionDigits) {
      return Number(aNumber).toFixed(fractionDigits);
    };
  });

   $mod.x = $mod.TDoubleHelper.toFixed.call({p: $mod, get: function () {
       return this.p.ReturnValue;
     }, set: function (v) {
       this.p.ReturnValue = v;
     }},Math.sin(10.1) * 2.5,2);


Personaly, I don't like being able to specify a type helper, jsut because
Class helpers are not attractive. It's a kind of weird thing :)

I just want to determine X and cut to 2 decimals, using type helper, this
weird syntax:

  x := ReturnValue.toFixed(sin(rad) * r, 2); // type helpers it's weird and
generates extra code





--
Sent from: http://pas2js.38893.n8.nabble.com/


More information about the Pas2js mailing list