简体   繁体   English

如何jsdoc注释BackboneJS代码?

[英]How to jsdoc annotate BackboneJS code?

Has anyone ever documented BackboneJS code with JSDoc? 有没有人用JSDoc记录BackboneJS代码?

I'm having problems annotating Backbone constructs such as: 我在注释Backbone构造时遇到问题,例如:

User = Backbone.Model.extend({

    defaults: { a: 1 },

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

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

Any advice appreciated. 任何建议表示赞赏 Thanks. 谢谢。

I think it works somehow like this, if you're talking about the JSDoc Toolkit: 如果您在谈论JSDoc工具包,我认为它在某种程度上是这样的:

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

The important bit is the position of the @lends tag! 重要的一点是@lends标签的位置!

It can be a bit tricky, but if this doesn't work try out some of the other examples: http://code.google.com/p/jsdoc-toolkit/wiki/CookBook 这可能有点棘手,但如果这不起作用,请尝试其他一些示例: http//code.google.com/p/jsdoc-toolkit/wiki/CookBook

chris_b's answer helped me a lot, the sample as well as the link. chris_b的回答对我有很大帮助,样本以及链接。 I had to drop the @class annotation, though, or it would generate two entries for the class. 不过,我不得不删除@class注释,否则会为该类生成两个条目。 Furthermore, I'm adding this answer to show how to annotate static class members (class level constants). 此外,我正在添加这个答案,以展示如何注释静态类成员(类级别常量)。

(We use require.js.) (我们使用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;
});

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

相关问题 如何使用 JSDoc 注释 Express 中间件? - How to annotate Express middlewares with JSDoc? 如何在 JSDoc 中使用可选属性注释匿名对象 - How to annotate anonymous object with optional property in JSDoc 如何在JSDoc中注释“@ readonly-but-modified-internal”成员/属性? - How to annotate “@readonly-but-modified-internally” members / properties in JSDoc? 使用 JSDoc 如何注释解构的重命名函数参数? - Using JSDoc how would I annotate a destructured renamed function argument? 如何在 JSDoc 中使用 Function 类型注释 object 类型,该类型具有可变数量的 arguments? - How to annotate an object with Function type that has variable number of arguments in JSDoc? JSDoc-如何记录代码区域 - JSDoc - how to document region of code 使用JSDoc + RequireJS + BackboneJS的模块和类 - Modules and classes using JSDoc + RequireJS + BackboneJS TypeScript - 如何在此代码中注释类型? - TypeScript - How to annotate types in this code? 如何在VSCode中使用JSDoc @template注释ES5类,以防止出现checkJS错误? - How to annotate an ES5 class with a JSDoc @template in VSCode to prevent checkJS errors? 我如何使用 jsdoc 注释注释 React.forwardRef 以便智能感知可以显示在底层组件中? - How do i annotate React.forwardRef with jsdoc comments so that intellisense can show up for the underlying component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM