如何jsdoc注释BackboneJS代码?

sea*_*ean 16 javascript jsdoc backbone.js

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

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

User = Backbone.Model.extend({

    defaults: { a: 1 },

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

    doSomething: function (p) {
        // ...
    }
});
Run Code Online (Sandbox Code Playgroud)

任何建议表示赞赏 谢谢.

chr*_*s_b 27

如果您在谈论JSDoc工具包,我认为它在某种程度上是这样的:

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

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

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


Ris*_*nha 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;
});
Run Code Online (Sandbox Code Playgroud)