[英]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.