Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax for parameters with properties #2

Closed
nene opened this issue Jan 11, 2011 · 2 comments
Closed

Syntax for parameters with properties #2

nene opened this issue Jan 11, 2011 · 2 comments

Comments

@nene
Copy link
Member

nene commented Jan 11, 2011

Having Markdown support already alleviates this issue, but it would be nice to have a special syntax for this.

One possibility is to adopt the same syntax that jsdoc-toolkit supports:

/**
  * @param userInfo Information about the user.
  * @param userInfo.name The name of the user.
  * @param userInfo.email The email of the user.
  */
 function logIn(userInfo) {
        doLogIn(userInfo.name, userInfo.email);
 }

Another option I've been thinking is to re-use @cfg:

/**
  * @param userInfo Information about the user.
  * @cfg name The name of the user.
  * @cfg email The email of the user.
  */
 function logIn(userInfo) {
        doLogIn(userInfo.name, userInfo.email);
 }

This greatly reduces the amount of duplication. If the function accepts only one parameter (as such functions often do), maybe we could even skip the @param completely:

/**
  * @cfg name The name of the user.
  * @cfg email The email of the user.
  */
 function logIn(userInfo) {
        doLogIn(userInfo.name, userInfo.email);
 }

The only downside is that when you have just one @cfg then the doc-comment will be interpreted as class-level config option, but having a function parameter object with just one possible property is a bit silly and one can always force parsing doc-comment as method doc-comment by using @method.

The best would be to support both syntaxes.

nene added a commit to nene/jsduck that referenced this issue Jun 30, 2011
@nene
Copy link
Member Author

nene commented Jul 25, 2011

Thinking of taking the jsdoc-toolkit-style approach:

/**
 * @cfg {Function} handler A callback that gets passed the following parameters:
 * @cfg {Object} handler.userInfo A userinfo object:
 * @cfg {String} handler.userInfo.name The name of the user.
 * @cfg {String} handler.userInfo.email The email of the user.
 */
handler: Ext.emptyFn,

Same thing with method parameters:

/**
 * @param {Function} handler A callback that gets passed the following parameters:
 * @param {Object} handler.userInfo A userinfo object:
 * @param {String} handler.userInfo.name The name of the user.
 * @param {String} handler.userInfo.email The email of the user.
 * @param {Object} scope Scope for the callback.
 */
doSomething: function(handler, scope) {
},

The main question is how to document the return value of the function. We could simply treat the name "return" specially:

/**
 * @cfg {Function} handler A callback that gets passed the following parameters:
 * @cfg {String} handler.return The formatted value
 */
handler: Ext.emptyFn,

This shouldn't cause any conflicts because "return" is a reserved keyword and you can't use it as function parameter name.

@nene nene closed this as completed Aug 2, 2011
@nene
Copy link
Member Author

nene commented Aug 2, 2011

Finally, this is now implemented.

arthurevans pushed a commit to arthurevans/jsduck that referenced this issue Sep 12, 2012
[TIDOC-747] Fixed issue with punctuation in section titles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant