Reputation: 7892
I feel extremely stupid to ask this and I'm sure the answer is pretty obvious, but I just can't figure that out on my own.
Take this line of code (can I refer to it as a "line of code"? I know it's like a "blueprint", but how does one call it?) from jQuery documentation:
jQuery.get( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )
How to read that? Why are the commas placed after the opening brackets? What does that mean?
Upvotes: 4
Views: 174
Reputation: 8145
This kind of notation you call "blueprint" is actually syntax of the call described using Backus-Naur Form (BNF) notation. It is a notation frequently used in computer science to describe grammar of a language.
It is not difficult once you grab basic concepts (use e.g. Wikipedia to learn more). This exact example is quite easy to read once you know that parts inside [
and ]
are optional alternatives with 0..1 occurrences. So there are as many ways to read it as there are combinations which include/exclude the parts in brackets.
Upvotes: 2
Reputation: 75565
It should be read as a function call with url
as a required argument and all other arguments optional.
The commas are placed inside the opening brackets because they are optional, just like the arguments. In other words, you need the extra comma if you are providing an additional argument.
Another point of confusion might be success(data, textStatus, jqXHR)
.
This is specifying that you should pass in the name of a function which takes three arguments, and will be executed if the request succeeds.
Upvotes: 4