如何jsdoc注释BackboneJS代码?

时间:2011-06-22 11:08:31

标签: javascript backbone.js jsdoc

有没有人用JSDoc记录BackboneJS代码?

我在注释Backbone结构时遇到问题,例如:

User = Backbone.Model.extend({

    defaults: { a: 1 },

    initialize: function () {
        // ...
    },

    doSomething: function (p) {
        // ...
    }
});

任何建议表示赞赏。感谢。

2 个答案:

答案 0 :(得分:27)

如果你在谈论JSDoc工具包,我认为它的工作原理是这样的:

User = Backbone.Model.extend(
/** @lends User.prototype */
 {
  /**
   * @class User class description
   *
   * @augments Backbone.Model
   * @constructs
   *
   * Text for the initialize method
   */
    initialize: function() {}
})

重要的一位是@lends标签的位置!

这可能有点棘手,但如果这不起作用,请尝试其他一些示例:http://code.google.com/p/jsdoc-toolkit/wiki/CookBook

答案 1 :(得分:5)

chris_b的回答帮了我很多,样本和链接。不过,我不得不删除@class注释,否则会为该类生成两个条目。此外,我正在添加此答案以展示如何注释静态类成员(类级别常量)。

(我们使用require.js。)

define([
    'jquery', 'lodash', 'backbone'
], function($, _, Backbone) {
    "use strict";

    /**
     * Enumeration of constants that represent the different types of Hedgehogs.
     * @memberof models/Hedgehog
     * @enum {string}
     * @readonly
     */
    var types = { 'type1': 'Type 1', 'type2': 'Type 2' };

    var Hedgehog = Backbone.Model.extend(
    /** @lends models/Hedgehog.prototype */
    {
        /**
         * This is the model for Hedgehogs.
         *
         * @augments external:Backbone.Model
         * @constructs
         */
        initialize: function() {
            // your code
        },

        // some more methods
    }, {
        // static class members
        "types": types
    });
    return Hedgehog;
});
相关问题