Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

KRL allows the parameters of functions and user-defined actions to have default values. If the function or action is called without a parameter, that parameter gets its defaults value. Furthermore, arguments can be passed to functions and user-defined actions using named arguments. 

Here is an example of the function foo() with two arguments, bar and baz. You can see that each has been given a default value:

Code Block
languagejs
themeConfluence
foo = function(bar = 2, baz = bar + 3){
    bar + baz
}

This function could be called in several ways:

Code Block
languagejs
themeConfluence
a = foo() // a has the value 7
a = foo(5) // a has the value 13 because bar gets the value 5 and baz gets its default value
a = foo(5, 6) // a has the value 11 since bar gets the value 5 and baz gets the 6
a = foo(baz = 6) // a has the value 8 since bar get its default value 2 and baz get the value 6
a = foo(bar = 5) // a has the value 13 because bar gets the value 5 and baz gets its default value
a = foo(bar = 5, baz = 6) // a has the value 11 since bar gets the value 5 and baz gets the 6
a = foo(baz = 6, bar = 5) // a has the value 11 since bar gets the value 5 and baz gets the 6

The same syntax is used in user-defined action with the same effect on parameter values.