Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2019-09

Fwd: Verbose Code

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

warleyalex
to helioroots roots

one trick is to define an fake external class that descends from the TJSObject, there's no need to have a constructor.

type
  TFunc = reference to function: Double;
  TCircle = class external name 'Object' (TJSObject)
    radius: Integer;
    area: TFunc;
  end;
(..)
var
  circ : TCircle;
begin
  circ := TCircle.new;
  circ.radius:= 10;
  circ.area := function(): Double
  begin
    Result := PI * circ.radius * circ.radius;
  end;