2013-02-28 2 views
3

Я пытаюсь документировать функциональность в классе User, который находится в закрытии. Как это сделать с JsDoc3?Как документировать Закрытие

Вот что у меня есть:

/** 
    @class User 
    @classdesc This is the class that describes each user. 
*/ 
(function($){ 

    var _defaults = { 
     'first_name': '', 
     'last_name': '' 
    }; 

    /** 
     @constructor 
    */ 
    function User(options) { 
     this.options = $.extend({}, _defaults, options); 
    } 

    /** 
     @method 
     @desc Returns the combined first name and last name as a string 
     @returns {string} 
    */ 
    User.prototype.getName() = function(){ 
     return this.options.first_name + this.options.last_name; 
    }; 

    window.User = User; 

}(jQuery)); 

ответ

1

Я не знаю, почему jsdoc3 решает игнорировать документы в рамках закрытия, но, по крайней мере, один Обходной использовать @memberOf тег явно указать, какой класс A Способ относится к:

/** 
* @memberOf User 
* Returns the combined first name and last name as a string 
* @returns {string} 
*/ 
User.prototype.getName = function(){ 

Другое дело, следует отметить, что вам не нужно использовать @desc и @classdesc теги - это автоматически добавляются самой jsduc3, это больше деталей реализации, что эти теги EXI st на всех.

2

У меня был успех в этом методе. (добавляется в плагин с плагином, поэтому комментарий к MIT-лицензии включен)

См. использование @global + @class и @global на прототипе. Это похоже на это.

Код скопирован ниже: Наслаждайтесь & сделайте это лучше, пожалуйста.

/** 
* jQuery lightweight plugin boilerplate 
* Original author: @ajpiano 
* Further changes, comments: @addyosmani 
* Licensed under the MIT license 
*/ 

;(function ($, window, document, undefined) { 

var pluginName = "Application", 
    defaults = { 
     propertyName: "value" 
    }; 

/** 
* @global 
* @class Application 
* @description MASTER: Sets up and controls the application 
* 
* @returns Object 
*/ 
function Application(element, options) { 
    this.element = element; 
    this.options = $.extend({}, defaults, options) ; 
    this._defaults = defaults; 
    this._name = pluginName; 
    this.init(); 
    window[pluginName] = this; 
} 

/** @global */ 
Application.prototype = { 

    /** 
    * @description call pre-life initialisations and tests here 
    */ 
    init: function() { 

     var that = this; 
     that._build(); 
     that._setNotifications(); 
    }, 

    /** 
    @description Set up a pub sub for global notifications such a state-changes. 
    */ 
    _setNotifications: function(el, options) { 
     console.log('Application=>setNotifications()'); 
    }, 


    /** 
    @description All environment setup done we now call other plugins. 
    */ 
    _build: function(el, options) { 
     console.log('Application=>build()'); 
    } 
}; 

$.fn[pluginName] = function (options) { 
    return this.each(function() { 
     if (!$.data(this, "plugin_" + pluginName)) { 
      $.data(this, "plugin_" + pluginName, 
      new Application(this, options)); 
     } 
    }); 
}; 




})(jQuery, window, document); 
0

В моем случае закрытие было в одном файле и использовать словарь, чтобы экспортировать свои объекты так, используя @file и @exports DicName метки в обзоре и @namespace тег для словаря сделал трюк в заставляя их задокументировать.

/** 
    @file myFileWithClosure 
    @exports DicName 
*/ 
(function($){ 

    /** @namespace */ 
    DicName = {}; 

    ... 

Глобальное не требуется.

Смежные вопросы