2014-04-08 5 views
2

필요에 따라 여러 객체를 프로토 타이핑 할 중첩 된 네임 스페이스를 구성한다고 가정 해 보겠습니다. 기본적으로 window.blah.foo 객체는 비어 있습니다. 그런 다음 모든 하위 객체와 함수를 하나의 프로토 타입으로 프로토 타입합니다. 우리가 아래에있는 것처럼 문서화 할 때 모든 내부 함수를 전역으로 표시합니다. 이제 같은 방법으로 수십 개의 파일을 만들었다 고 상상해보십시오. .bar1(), bar2() 및 bar3() 함수가 window.blah.foo 객체의 메소드이며, 특히 인스턴스화가이 파일 외부에서 여러 번 수행 될 때이를 어떻게 문서화 할 수 있을까요?프로토 타입 상속을 문서화하는 JSDoc

/** 
* Blah - Our very own global Namespace 
* @namespace 
* @type {object} 
* @global 
* @public 
*/ 
window.blah = window.blah || {}; 

/** 
* Immediately-Invoked Function Expression (IIFE). 
* @function 
* @param {object} w - Global window object. 
* @returns {Object} window.blah.foo 
*/ 
(function (w) { 

    // strict JS 
    'use strict'; 

    /** 
    * Create instance of w.blah.foo constructor 
    * @constructor 
    */ 
    w.blah.foo = function() { 

    }; 

    /** 
    * Append properties and methods to an instance of window.blah.foo 
    * @constructor 
    */ 
    w.blah.foo.prototype = { 

     /** 
     * Dummy function to return the number 1. 
     * @method bar1 
     */ 
     bar1: function() { 
      console.log(1); 
     }, 

     /** 
     * Dummy function to return the number 2. 
     * @method bar2 
     */ 
     bar2: function() { 
      console.log(2); 
     }, 

     /** 
     * Dummy function to return the number 3. 
     * @method bar3 
     */ 
     bar3: function() { 
      console.log(3); 
     } 

    }; 

}(window)); 

답변

3

다음은 그들이 속한 barX 방법을 이동합니다. jsdoc이 IIFE를 문서화 한 도크 렛과 아무 관련이 없음에 유의하십시오. 적절한 장소에서 방법을 얻는 열쇠는 /** @lends blah.foo# */입니다. @lends의 설명서를 참조하십시오. #blah.foo에 대여 항목이 클래스의 인스턴스에 속하는지 jsdoc을 알려줍니다. 자세한 내용은 namepaths의 설명서를 참조하십시오.

/** 
* Blah - Our very own global Namespace 
* @namespace 
* @global 
*/ 
window.blah = window.blah || {}; 

/** 
* Immediately-Invoked Function Expression (IIFE). 
* @function 
* @param {object} w - Global window object. 
* @returns {Object} window.blah.foo 
*/ 
(function (w) { 
    // strict JS 
    'use strict'; 

    /** 
    * Create instance of w.blah.foo constructor 
    * @constructor 
    * @name blah.foo 
    */ 
    w.blah.foo = function() { 

    }; 

    /** @lends blah.foo# */ 
    w.blah.foo.prototype = { 

     /** 
     * Dummy function to return the number 1. 
     */ 
     bar1: function() { 
      console.log(1); 
     }, 

     /** 
     * Dummy function to return the number 2. 
     */ 
     bar2: function() { 
      console.log(2); 
     }, 

     /** 
     * Dummy function to return the number 3. 
     */ 
     bar3: function() { 
      console.log(3); 
     } 

    }; 

}(window)); 
+0

감사합니다! 나는 어딘가에서 꼬리표를 놓쳤다는 것을 알았다. –

관련 문제