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

Easy way to document callbacks #33

Open
hazeledmands opened this issue Nov 10, 2013 · 1 comment
Open

Easy way to document callbacks #33

hazeledmands opened this issue Nov 10, 2013 · 1 comment

Comments

@hazeledmands
Copy link
Contributor

This is a pretty common trope in JS code:

someAsyncFunction('parameter1', function parameter2(err, result) {
    if(err) {
          console.err(err.toString());
              return;
                }
                  console.log(result);
});

or as in underscore or lazy.js:

lazy([1,2,3]).map(function(index, value) {
    return index + value;
}).toArray();

Right now, when documenting these API's, we have to resort to something like:

/**
* Does some async thing!
* @argument {string} foo This is very unimportant.
* @argument {function} callback When we've finished our calculation, we call this function and provide it two arguments -- the first is an error, which will be `null` if everything works out okay, and the second is an instance of `HolyGrail` which will make all your dreams come true.  
*/
someAsyncFunction: function(foo, callback) {
     // ...
}

This seems less than ideal. JSDoc provides the @callback tag, which might be the optimal solution here. What do you think?

@dtao
Copy link
Owner

dtao commented Nov 10, 2013

Yeah, I think I agree here. I was also planning on adding support for the @typedef tag soon as well; I think @callback support could be added around the same time.

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

2 participants