2013-02-28 32 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標籤明確地告訴該班一方法屬於:

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

另一個要注意的是,你不需要使用@desc@classdesc標籤 - 這些都是由jsduc3本身自動添加的,它更是一個實現細節的,這些標籤EXI一切。

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 = {}; 

    ... 

沒有全球所需。

相關問題