【问题标题】:JSDoc3 with Dojo and AMD带有 Dojo 和 AMD 的 JSDoc3
【发布时间】:2014-12-12 07:35:24
【问题描述】:

我正在尝试正确处理我的 JS 文档。我正在使用 Dojo,以及基于它构建的其他一些复杂的框架,我将省略细节。关键是这个框架使用了 AMD 模块。我希望我的 JSDoc 工作。

这是我目前所拥有的:

/**
 * Creates a button instance that launches a document entry template selector
 * @module widgets/instance/AddButton
 */
define([
    "dijit/_TemplatedMixin",
    "dijit/_WidgetBase",
    "dojo/_base/declare",
    "dojo/_base/lang",
    "dojo/on",
    "kwcn/services/request",
    "kwcn/widgets/AddContentDialog"
], function (_TemplatedMixin, _WidgetBase, declare, lang, on, request, AddContentDialog) {
    return declare('AddButton', [_WidgetBase, _TemplatedMixin], /** @lends module:widgets/instance/AddButton */{
        id: 'add-button',
        contentList: null,
        templateString: '<button class="btn btn-link toolbar-link"><i class="fa fa-lg fa-file"></i> Add Document</button>',
        addContentItem: null,
        type: null,
        /**
         * @constructs
         * @param args
         * @param args.type {string} The type of content item
         * @param args.contentList {ContentList} The instance of [ContentList]{@link module:widgets/contentList/ContentList} in scope
         */
        constructor: function (args) {
            declare.safeMixin(this, args);
        },
        /**
         * @private
         */
        postCreate: function () {
            console.log("creating the add content button...");
            this.addContentItem = new AddContentDialog({
                repository: request.repository(),
                hasCase: false
            });
            this.own(on(this.domNode, 'click', lang.hitch(this, 'show')));
        },
        /**
         * @public
         */
        show: function () {
            request.inboundFolder().then(lang.hitch(this, function (folder) {
                this.addContentItem.showAddDocument(null, folder);
            }));
        }
    });
});

结果:

这个结果还不错。但它推断我的成员是静态的。 WebStorm 似乎将它们正确地推断为成员,但 jsdoc3 生成器却没有。从我读到的内容来看,我不应该指定@memberof,因为@lends 应该负责这一点。有什么我做错了吗?任何一般性建议将不胜感激。我阅读了 JSDoc3 文档,但是在将 AMD 添加到等式时,很多结构看起来都模糊不清。

【问题讨论】:

    标签: dojo amd jsdoc3


    【解决方案1】:

    您需要将实例属性借给原型,而不是对象本身:@lends module:widgets/instance/AddButton#。注意末尾的#,它是.prototype 的简写。

    另外请注意,jsdoc3 有很多与处理非 CommonJS 模块相关的错误,因此您可能需要做一些额外的修改才能使其正常工作。

    【讨论】:

    • 漂亮!就像你说的那样有效。现在我看到它完全有道理。
    猜你喜欢
    • 2012-02-29
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 2014-07-12
    • 1970-01-01
    相关资源
    最近更新 更多