[Pas2js] Possible feature? keep the original JS overload behavior

silvioprog silvioprog at gmail.com
Fri Dec 21 18:28:20 CET 2018


On Fri, Dec 21, 2018 at 1:54 PM Michael Van Canneyt <michael at freepascal.org>
wrote:

> Why not simply declare
>
> function myfoo: string; varargs;external name 'foo';
>

well, it is not a variadic situation, because the arguments must be named.
However, ...

Because if you declare all arguments as jsvalue, it makes no sense to
> create all
> overloads, there is no type checking.


... I agree about this above, and I've used the varargs facility.

Anyway, it would be nice such feature like this, but at this moment I can't
get an idea of a possible pascal-ish syntax. :-/ So a compiler option would
be welcome, allowing "omit default parameters". E.g:

procedure foo(const a: string = ''; const b: string = ''); external name
'foo';

begin
  foo;
  foo('abc');
  foo('abc', 'def');
end.

./pasjs -Jo=js test.pp

would generate:

foo();
foo("abc");
foo("abc",123);

What we could do is extend varargs to accept a count:
>
> function myfoo: string; varargs 2;external name 'foo';
>
> So you cannot pass more arguments than the original function supports, the
> compiler could check the number of var args passed.


IMHO this should not be implemented, because the variadic idea is precisely
solve situations that the number or arguments is unknown. :-)

--
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20181221/d12a8bb0/attachment-0001.html>


More information about the Pas2js mailing list