News
We’re asking you to select a content label when starting a new topic in the Discussions area. Read more to find out why.
Choose Language Hide Translation Bar
Highlighted
senatorx
Level III

Function overloads in JSL?

Hey,

I've just started working with Functions in JSL.  I am wondering if there is a way to create overload functions similar to C++/C#.

Even if JSL doesn't officially support it, there also may be a way to create pseudo overloads, such as with VBScript using CASE / WHERE.  Has anyone tried this?

Thanks!

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
XanGregg
Staff

Re: Function overloads in JSL?

There's no overloading; however, you can make arguments optional so that, for instance, f(a) and f(a, b) can call the same function:

       f = Function({x, y=0}, sqrt(x * x + y * y));

You can also check the types of the arguments with functions like Is Number() within a nested if(), which sounds like your VB example.

View solution in original post

0 Kudos
2 REPLIES 2
Highlighted
XanGregg
Staff

Re: Function overloads in JSL?

There's no overloading; however, you can make arguments optional so that, for instance, f(a) and f(a, b) can call the same function:

       f = Function({x, y=0}, sqrt(x * x + y * y));

You can also check the types of the arguments with functions like Is Number() within a nested if(), which sounds like your VB example.

View solution in original post

0 Kudos
Highlighted
senatorx
Level III

Re: Function overloads in JSL?

Thanks, I found a good discussion on optional arguments after doing a search.  This provides the same capability I need.  It sounds like optional arguments are created by providing default values for additional arguments.  You can also give a List or an Associative array to the function, and change the bahavior of the function based on the number of values in the list or which keys are present in the associative array.  Using a list requires inputs to be carefully placed in the correct order when calling the function, but with the associative array the arguments can be provided in any order.