0

How do I document functions inside of a return? In this example, I need then() documented. I have tried adding @memberOf and @name to get it to generate. Nothing seems to work for me.

/**
 * The description for the outer function 
 * @param {string} test Example argument
 * @return {Object}
 */
example.func = function(test) {
   return {
       /**
        * The description for the inner "then" function
        * @param {Function} cb The callback function
        */
       then: function(cb) { }
   }
}

Update Added JSDoc comments to the top to prevent confusion.

1

1 Answer 1

1

JSDoc comments must be above the declaration, the return statement must be declared with @returns {type} value (note that @return is a synonyms)

/**
 * Returns the sum of a and b
 *
 * @param {Number} a
 * @param {Number} [b = 0]
 * @returns {Number}
 */
function sum(a, b = 0) {
    return a + b;
}
Sign up to request clarification or add additional context in comments.

4 Comments

I'm trying to document a function inside a return - like a promise. The outside function had its own jsdoc comment but didn't include it inside de the example to make it concise.
If you are returning a Promise, you must do: @returns {Promise}.
It's not a promise. I said like a promise. See the above code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.