繁体   English   中英

JSDoc-如何记录有限数量的值及其参数的类型?

[英]JSDoc - How to document a limited number of values and their type for a parameter?

我正在使用JSDoc记录方法。 正如你可以看到下面我要介绍的参数to ,我需要的文件,该值类型的stringnumber 和接受的值只有这一个:

TYPE:     VALUES ONLY ACCEPTED:
string - 'move:next'
string - 'move:prev'
number -  any number

如何将此信息传递给JSDoc?


        /**
         * Description here
         * @memberof app
         * @method _moveTo
         * @param {string|number} [to=move:next] [to=move:prev] - Some description.
         */

        _moveTo: function (to) {
            var isValid = true,
                goToIndex = this._focus,
                hasItem;
            if (to === 'move:next') {
                goToIndex++;
            } else if (to === 'move:prev') {
                goToIndex--;
            } else if (typeof to === 'number') {
                goToIndex = to;
            } else {
                isValid = false;
            }
            // more code...
        }

只需用'|'分隔可接受的字符串,如下所示:

/**
 * ...
 * @param {'move:next'|'move:prev'|number} to - Some description.
 * ...
 */

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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