You often see this kind of syntax for describing methods:
Math.max([value1[,value2, ...]])
Function.prototype.call (thisArg [ , arg1 [ , arg2, … ] ] )
Why are parameters denoted like this using brackets and leading commas?
You often see this kind of syntax for describing methods:
Math.max([value1[,value2, ...]])
Function.prototype.call (thisArg [ , arg1 [ , arg2, … ] ] )
Why are parameters denoted like this using brackets and leading commas?
Brackets are used for argument specifications to indicate that the argument is optional.
This likely comes from the format used in UNIX/Linux man pages (although they may have borrowed that syntax from some other earlier source for all I know). The man page on man-pages has a description of how arguments should be represented (emphasis mine):
SYNOPSIS briefly describes the command or function's interface. For commands, this shows the syntax of the command and its arguments (including options); boldface is used for as-is text and italics are used to indicate replaceable arguments. Brackets (
[]) surround optional arguments, vertical bars (|) separate choices, and ellipses (...) can be repeated.
Javascript doesn't have strict requirements for function parameters. functions can have as many parameters as you want to put in them. You can call a function that only has two parameters with 3 parameters and javascript will ignore the ones that aren't noted.
However, the order of the variables is still important. In other words, you can't use just the first and third parameters, if you want to use the third parameter you have to specify something for the second.
the square brackets mean the parameter is not required. The comma is just to tell you that you need a comma if you are going to specify a parameter there.