Often when reading documentation on what arguments can be passed to a method, I see brackets used within the arguments list like this:
What do the brackets mean in this context? Why are the commas inside the brackets?
Often when reading documentation on what arguments can be passed to a method, I see brackets used within the arguments list like this:
What do the brackets mean in this context? Why are the commas inside the brackets?
required
[optional]
<required>
[<optional>, <but both needed>]
.
This is almost always the case.
The brackets around a parameter means that it is optional.
When written separately like that, it means that you can use any of the parameters in any combination. The method determines what you use from the data type of the values. All these combinations can be used for that method:
.animate(properties, duration, easing, complete)
.animate(properties, duration, easing)
.animate(properties, duration, complete)
.animate(properties, duration)
.animate(properties, easing, complete)
.animate(properties, easing)
.animate(properties, complete)
.animate(properties)
You can see brackets used in other ways than around each parameters. For example:
.method(p1 [, p2 [, p3]])
This means that the second and third parameters are optional, and the third parameter can only be used if the second parameter is there.
The square brackets mean they are optional parameters. You need not pass the optional parameters. .animate(properties)
will work . Also the commas are inside the bracket because if it were outside, they would trail
animate(properties, [duration]) would mean properties and , are mandatory, whereas duration is not... It would like : animate(properties,)