简体   繁体   中英

JavaScript class has setter that returns this. How do I document this in JsDoc?

Sample code:

var myObject = (function() {
    var M;

    M = function() {
    }

    M.prototype = {
        constructor: M,
        setSomeProperty = function(someValue) {
            // Do Stuff
            return this; // For chaining purposes
        }
    }

    return M
}());

What would the @returns tag look like when documenting the setSomeProperty method?

It would look like this:

@returns {M} <code>this</code>

{M} indicates the class of what is returned, and <code>this</code> clearly indicates what is returned. If you use the markdown plugin:

@returns {M} `this`

A more verbose version would be:

@returns {M} The instance on which this method was called.

Or you could omit the class information and let the reader infer it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM