2

Background:

I know that in Python you can set a value of a default parameter by using the name of the parameter when calling the method.
Here's a quick example of what that looks like in Python (with the results):

def do_something(first, second=2, third=3):
    print(first, second, third)

do_something(1)             // (1, 2, 3)
do_something(1, 22)         // (1, 22, 3)
do_something(1, None, 33)   // (1, None, 33)
do_something(1, third=33)   // (1, 2, 33)

Actual question:

How can I send a value for a default parameter in Javascript using the name (and not the location) of the parameter?

So far, I have found that you can:

  1. Send undefined values for the parameters you don't want to change until you get to the position of the parameter you do want to change.

  2. Change the function itself to receive an object and then send an object to the function (as described here).

Does anyone know of a way this can be done using the name of the parameter like the Python example above?

shapiro yaacov
  • 2,308
  • 2
  • 26
  • 39

0 Answers0