Variable number of function arguments

375 views
Skip to first unread message

simon

unread,
Aug 27, 2007, 11:06:55 AM8/27/07
to JsDoc Toolkit Users
Hi everyone
How would I document the following function that can be passed an
unlimited number of optional arguments ?

List.prototype.RemoveItem = function() {
var Len = arguments.length;
if (Len > 0) {
// remove specified items
var i = 0;
for (; i < Len; i++) {
this.El.removeChild(arguments[i]);
}
}
else { // remove all
while (this.El.hasChildNodes()) {
this.El.removeChild(this.El.firstChild);
}
}
}

Any ideas ?

Michael Mathews

unread,
Aug 27, 2007, 5:12:03 PM8/27/07
to jsd...@googlegroups.com
Hi Simon,

This question has come up previously (see thread entitled "Optional
arguments...") and there isn't any official way, but one possible
solution is this:

/**
* @param [...] Zero or more child nodes. If zero then ...
otherwise ....
*/

The square brackets indicate an optional parameter, and the ... would
(to me) indicate "some arbitrary number."

Another possibility is this...

/**
* @param [arguments] The child nodes.
*/

Either way should communicate what you mean.

Regards,
Michael

simon

unread,
Aug 28, 2007, 3:02:02 AM8/28/07
to JsDoc Toolkit Users
Sorry for not searching on that subject first (You just could have
said: RTFM!).

Explanation: I was simply confused by the fact, that there is more
than one optional argument, but I don't know how many. I thought I
would have to document each one of them with a @param, but how's that
possible if I don't know how many there are...

So I just did as you suggested:
* @param {object} [arguments] zero or more nodes


Thank you Simon

Michael Mathews

unread,
Aug 28, 2007, 4:59:58 AM8/28/07
to jsd...@googlegroups.com
You're very welcome, Simon. My general view on all such questions is that documentation is a form of human-to-human communication, and as such the best answer is always going to be the one that makes the most sense to your intended audience. There rarely is a single cut-and-dried answer to that.

And I officially hate the "RTFM" response and hereby grant permission to anyone to smack me if I ever utter it. I try to take the view that all users are smart and sincere and if the information were reasonably easy to find they would have already. The closest I ever plan to get to RTFM is: "You can find that information here," or "I'll try to make that information easier to find in the manual for you."

ITTMTIETFITMFY? erm... maybe not.

Regards,
Michael
Reply all
Reply to author
Forward
0 new messages