I’ve saw two styles while reading built-in objects for JavaScript.
// Let's assume that all callback parameters are explained at h3.Parameters, regardless of its style.
someFunction(callback[, optionalArg]); // first style, callback params are not written here.
someFunction(callback(cbArg[, cbOptionalArg])[, optionalArg]) // second style, callback params are explicitly written here.
ECMA-262 6th edition uses the first style (Array.prototype.map( callbackfn [ , thisArg ] )) so is it safe to think that I should prefer callbacks without parameters?
This is not something I’ve thought about, but it is a good idea for us to do this consistently. Thanks for bringing it up.
In the WebAPI documentation, I tend to always write it without including the cb params, as it is less confusing. The cb params can then be explained somewhere below.
I think @fscholz also stuck to this style in the JS built-ins docs, but confirming this would be good.
As a documentation, I prefer bracket syntax over multiline for its single line cleanliness. But I admit, I found it quite hard to grasp at the beginning.
Listing variations has its place too. For me, a good example of combining brackets + variations was Date constructor.
Maybe add a help button inside syntax boxes, which appears when hovered and links to some page, that describes syntax-box-syntax? I couldn’t find such page (yet), reading this Wikipedia is too much, and it would help to reduce questions such as this.
For the main topic:
I’ll prefer parameterless callbacks. Thanks! Syntax sections page needs updates too. It could be used as a help page.
Though I personally prefer traditional bracketed syntax for optionals, I conceded last year that expecting newcomers to know that syntax wasn’t logical, and so I’ve started using multiple lines of syntax forms to describe different sets of parameters to a function, and any optional parameters are just noted as optional using {{optional_inline}} on the <dt> line indicating the parameter name in the <dl> below. I can live with that.
Another option might be to use question marks ? instead of brackets, which is also what TypeScript uses for optional parameters in its extended syntax.