Operator Type:
Operator Scope of Action:
Operator Purpose:
Data Type Returned:
Operator First Added:
Operator in Current Baseline:
Operator Last Altered:
Operator Uses Loop Variable Argument:
Statement [other Statement type actions]
Document [operators of similar scope]
Data manipulation [other Data manipulation operators]
declaration
v9.1.0
Baseline
10.2.0
function
The function statement defines a user-defined function. Unusually as an operator function is used as a statement which is then followed by the definition of a user-named function fName. Atypically, trailing empty parentheses must not used by function. Thus:
function fName([argumentsList]){code}
Once defined a function is called in action code using the user-defined function name (here fName), as described here. Any function may several arguments or none at all. These are defined via a comma-delimited argumentsList. All arguments defined in the list are mandatory, unlike some action code operators which define some arguments as optional. In use, all defined arguments must be supplied, even if only as a default value, e.g. 0
for a number, etc.
All input arguments (the argumentsList) are available to use in code within the function. Thus by using the argument name as defined in the argumentsList, each argument's supplied value is retrievable anywhere within the function. Just as with a loop variable, the defined argument name is the code used to retrieve that argument's value.
As functions are more complex than other operators, their complete syntax and use is described in detail in the article on Functions and its sub-articles.
Function declarations may optionally specify the date type of their input arguments, as passed via argumentsList.
Private functions
From v10.2.0, a private function is a function that can only be called within the note in which it is defined. That note will usually be a library note.
The point of a private function is it allows for the scenario where two (or more) functions might have the same name as might arise if using library notes created by different people. Thus two (or more) library notes can each define private functions with identical names; each library note will use its own version of the private function. As long as functions are labelled private, they will only be callable from their containing note and not from other (library) notes. Be aware that if a note only contains one function it should not be made private—as nothing outside the note can call it.
A function is designated private by inserting the word private between the function's argument parentheses and the curly brace starting the function's code:
function fFunctionName(Args) private { ...code... }
White space(s) before/after the private is optional.
See also—notes linking to here: