2012-05-07 2 views
24

@param 태그는 속성의 문서화를 허용합니다.JSDoc 3 태그에서 객체의 속성을 문서화하는 방법 : @this

/** 
    * @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. 
    */ 

프로젝트에서 일하는 사람이 알고 있는지 궁금합니다. (문서가 아직 생성 중입니다 ...)

답변

40

는 인스턴스 멤버를 문서에 사용 @name Class#member :

그래서 여기에 사용하는 예제 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의

/** 
    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's 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's name 

    @name Component#name 
    @type String 
    @default "Component" 
    @readonly 
    */ 
    Object.defineProperty(this, 'name', { 
    value: options.name || 'Component', 
    writable: false 
    }); 
} 

이 결과는 구성원 섹션의 각 구성원, 유형, 기본값 및 읽기 전용 여부를 나열하는 설명서에 표시됩니다.

[email protected]에 의해 생성 된 출력은 다음과 같습니다 또한

JSDoc3 output

참조 :

+0

이 방법은''var Component = function() {'''paradigm? –

+0

이것은 나를 위해 작동하지 않습니다. 아무것도 생성되지 않습니다. –

5

개체의 속성을 설명하는 데 @property 태그를 사용하십시오.

@param은 메소드 또는 생성자의 매개 변수를 정의하는 데 사용됩니다.

@thisthis이 어떤 개체를 나타낼 지 정의하는 데 사용됩니다. https://github.com/jsdoc3/jsdoc

상세 정보 : http://usejsdoc.org/index.html

상세 정보 : http://code.google.com/p/jsdoc-toolkit/wiki/TagParam

+5

'Person' 인스턴스가 아닌'Person' 생성자의 속성입니다. 또한 설명서에 "This • Person"이라는 항목이 추가되어 유용하지 않습니다. – lazd

+0

''@this Person'' 태그는 간단히 생략 할 수 있습니다. 그것은''@ class'' 블록 내에서 중복됩니다. – Ignitor

1

클래스의 생성자 내에서 jsdoc은 문서화 된 속성이 클래스 intances에 속한다는 것을 자체적으로 인식합니다. 그래서이 충분해야한다 :

/** 
* @classdesc My little class. 
* 
* @class 
* @memberof module:MyModule 
* @param {*} myParam Constructor parameter. 
*/ 
function MyLittleClass(myParam) { 
    /** 
    * Instance property. 
    * @type {string} 
    */ 
    this.myProp = 'foo'; 
} 

를이 함수가 클래스 생성자는, 당신이 this가 참조 무엇인지 정의 할 수 @this를 사용할 수 있음을 jsdoc에 대한 명확하지 않으면 :이 실제로 문서가 생각

/** 
* @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'; 
}