Как документировать свойства объекта в теге JSDoc 3: @this
Тег @param
позволяет документацию о свойствах, например
/**
* @param {Object} userInfo Information about the user.
* @param {String} userInfo.name The name of the user.
* @param {String} userInfo.email The email of the user.
*/
Как я могу документировать свойства тега @this?
/**
* @this {Object}
* @param {String} this.name The name of the user.
* @param {String} this.email The email of the user.
*/
Мне интересно, знает ли кто-нибудь, кто работает над проектом. (Документы все еще создаются...)
Ответы
Ответ 1
Чтобы документировать экземпляры экземпляра, используйте @name Class#member
:
/**
Construct a new component
@class Component
@classdesc A generic component
@param {Object} options - Options to initialize the component with
@param {String} options.name - This component name, sets {@link Component#name}
@param {Boolean} options.visible - Whether this component is vislble, sets {@link Component#visible}
*/
function Component(options) {
/**
Whether this component is visible or not
@name Component#visible
@type Boolean
@default false
*/
this.visible = options.visible;
/**
This component name
@name Component#name
@type String
@default "Component"
@readonly
*/
Object.defineProperty(this, 'name', {
value: options.name || 'Component',
writable: false
});
}
Это приводит к разделу Members в документации, в которой перечислены каждый член, его тип, значение по умолчанию и только ли он для чтения.
Результат, сгенерированный [email protected], выглядит следующим образом:
![JSDoc3 output]()
См. также:
Ответ 2
Используйте тег @property
, чтобы описать атрибут объекта.
@param
используется для определения параметров метода или конструктора.
@this
используется для определения того, к какому объекту относится this
.
Итак, вот пример использования JSDOC 3.
/**
* @class Person
* @classdesc A person object that only takes in names.
* @property {String} this.name - The name of the Person.
* @param {String} name - The name that will be supplied to this.name.
* @this Person
*/
var Person = function( name ){
this.name = name;
};
JSDOC 3: https://github.com/jsdoc3/jsdoc
Дополнительная информация: http://usejsdoc.org/index.html
Дополнительная информация: http://code.google.com/p/jsdoc-toolkit/wiki/TagParam
Ответ 3
Внутри конструктора класса jsdoc реализует сам по себе, что документированные свойства принадлежат классам. Поэтому этого должно быть достаточно:
/**
* @classdesc My little class.
*
* @class
* @memberof module:MyModule
* @param {*} myParam Constructor parameter.
*/
function MyLittleClass(myParam) {
/**
* Instance property.
* @type {string}
*/
this.myProp = 'foo';
}
Если для jsdoc не ясно, что функция является конструктором класса, вы можете использовать @this
для определения того, что означает this
:
/**
* @classdesc My little class.
*
* @class
* @memberof module:MyModule
* @name MyLittleClass
* @param {*} myParam Constructor parameter.
*/
// Somewhere else, the constructor is defined:
/**
* @this module:MyModule.MyLittleClass
*/
function(myParam) {
/**
* Instance property.
* @type {string}
*/
this.myProp = 'foo';
}