【问题标题】:Documenting a Backbone constructor with JSDoc?用 JSDoc 记录 Backbone 构造函数?
【发布时间】:2013-12-09 11:38:04
【问题描述】:

我的应用程序有一个基本视图方法,它有一个 close 方法。直到我必须记录它为止,它都很好用;基本上我正在进行不必要的函数调用以正确记录它。由于 Backbone 已经有一个初始化函数,在这里再次调用它是没有意义的,占用了几行代码。但是如果我从代码中删除这个函数,则不会生成视图的文档。我的代码如下所示:

/**
 * @exports BaseView
 */
define(['backbone'], function( Backbone ) {
    'use strict';
    return Backbone.View.extend( /** @lends BaseView.prototype */ {
        /**
         * Base view with close method
         * @exports BaseView
         * @augments Backbone.View
         * @constructor
         */
        initialize: function() {
            Backbone.View.prototype.initialize.call(this);
        },
        /**
         * Removes the view from the DOM and unbinds all events.
         */
        close: function() {
            this.remove();
            this.unbind();
            if (this.onClose) {
                // Optionally, run additional cleanup methods.
                this.onClose();
            }
        }
    });
});

This question 让我在记录方面走上了正轨,但现在我想知道是否可以在 JSDoc 中记录初始化方法是从 Backbone.View 继承的,而不是编写函数调用。

如果有人能指出我正确的方向,我将不胜感激。谢谢。

【问题讨论】:

    标签: javascript backbone.js requirejs jsdoc


    【解决方案1】:

    以下内容是否符合您的要求?我刚刚删除了initialize 函数,将@name BaseView 添加到它前面的doclet 中,并删除了同一个doclet 中的@exports ...,因为它在那里看起来不正确。

    /**
     * @exports BaseView
     */
    define(['backbone'], function( Backbone ) {
        'use strict';
        return Backbone.View.extend( /** @lends BaseView.prototype */ {
            /**
             * Base view with close method
             * @augments Backbone.View
             * @constructor
             * @name BaseView
             */
    
            /**
             * Removes the view from the DOM and unbinds all events.
             */
            close: function() {
                this.remove();
                this.unbind();
                if (this.onClose) {
                    // Optionally, run additional cleanup methods.
                    this.onClose();
                }
            }
        });
    });
    

    【讨论】:

    • 真的不敢相信事情就这么简单。谢谢!
    猜你喜欢
    • 2015-02-10
    • 2014-01-26
    • 2015-04-06
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多