[Pas2js] How to insert inline {}

Michael Van Canneyt michael at freepascal.org
Mon Feb 6 14:30:14 CET 2023



On Thu, 26 Jan 2023, Ondrej Pokorny via Pas2js wrote:

> Hello,
>
> I'd like to use the DateTimePicker from https://getdatepicker.com .
>
> I declared an external class
>   TJSTempusDominus = class external name 
> 'tempusDominus.TempusDominus'(TJSObject)
>   public
>     constructor new(aElement: TJSElement);
>     constructor new(aElement: TJSElement; aOptions: TJSObject);
>   end;
>
> a simple constructor without options works fine:
>
>   fDateTimePicker := TJSTempusDominus.new(myElement);
>
> Can I somehow add inline options { my-property: false }?
>
> JS-code:
> window.datetimepicker1 = new tempusDominus.TempusDominus(
>   document.getElementById('datetimepicker1'), { my-property: false } );

Seems I missed this mail. So a late reply

How I do this usually, using new:

window.datetimepicker1 = new tempusDominus.TempusDominus(
    document.getElementById('datetimepicker1'), new(['my-property',false]));

You can recurse:
new([
   'my-property',false,
   'headers', new(
       ['content-type','application/json',
        'authorization','basic ABC'
       ])
    ]);


The new() function exists in the JS unit.

Michael.


More information about the Pas2js mailing list