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));
4

3 に答える 3

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 );
于 2013-10-04T17:17:18.793 に答える
1

jsdoc3 がクロージャ内のドキュメントを無視することを決定した理由はわかりませんが、少なくとも 1 つの回避策は、@memberOfタグを使用して、メソッドが属するクラスを明示的に伝えることです。

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

@desc注意すべきもう 1 つの点は、およびタグを使用する必要がないことです。@classdescこれらは jsduc3 自体によって自動的に追加されます。これらのタグが存在するのは実装の詳細です。

于 2013-03-03T19:44:02.423 に答える
0

私の場合、クロージャーは単一のファイルにあり、辞書を使用してそのオブジェクトをエクスポートしたため、概要で @file および @exports DicName タグを使用し、辞書に @namespace タグを使用すると、それらを文書化することができました。

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

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

    ...

グローバルは必要ありません。

于 2016-01-04T15:10:26.673 に答える