Skip to content
nene edited this page Mar 20, 2012 · 6 revisions

Synopsis:

@method [<name>]
Documentation for the method.

Documents the name of the method; or leaves the name for auto-detection and forces the documented entity to be treated as a method.

Example:

/**
 * @method area
 * Returns area of a circle
 * @param {Number} r Radius of the circle.
 * @return {Number} The area
 */

See [@param][] and [@return][] for further details on these most commonly used tags inside method documentation.

Auto-detection

This tag is auto-detected when doc-comment is right above function declaration. The following code is equivalent of the above one:

/**
 * Returns area of a circle
 * @param {Number} r Radius of the circle.
 * @return {Number} The area
 */
function area(r) {
}

Assignment of function literal works as well:

/**
 * Returns area of a circle
 */
var area = function(r) {
}

As does the use inside object literal:

{
    /**
     * Returns area of a circle
     */
    area: function(r) {
    }
}

JSDuck also understands Ext.emptyFn and treats the following as a method documentation:

/**
 * Returns area of a circle
 */
MyClass.prototype.area = Ext.emptyFn;

That's pretty much all. For example the following code would not be detected as a method if we weren't using the @method tag. JSDuck does however detect the name:

/**
 * @method
 * Returns area of a circle
 */
Array.forEach = (function() {
    if (Array.prototype.forEach) {
        return Array.prototype.forEach;
    }
    else {
        return function() { ... };
    }
})();