Reputation: 408
When going through docs or API's of JS libraries, I notice a "[," in params list.
Eg: vega.key(fields[, flat])
Does it mean optional arguments. How to interpret these.
Upvotes: 1
Views: 49
Reputation: 72226
It is a (widely-used) notation in documentation (and only in documentation; it is not valid syntax).
The part [, flat]
means the second argument is named flat
and it is optional.
The function can be called with two arguments (vega.key(fields, flat)
) or with only one argument (vega.key(fields)
). In this case, the comma must also be stripped (i.e. calling it as vega.key(fields,)
is invalid syntax.
You will also encounter this notation: vega.key(fields[, flat, ...])
or vega.keys(fields[, ...])
that means the function can be invoked with one or more arguments; fields
is required in the above notation, the others are optional.
Upvotes: 1
Reputation: 961
It means optional argument. You will often see
someFunc(arg1[, arg2[, arg3]])
which means arg2 and arg3 are optional. When arg2 is passed to the function, arg3 need not be, because it's optional, but arg2 is necessary when arg3 is passed.
Upvotes: 2