Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document Closures

I'm trying to document functionality within a class called User that is located within a closure - How do I do that with JsDoc3?

Here's what I have:

/**
    @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));
like image 233
alvincrespo Avatar asked Aug 08 '26 19:08

alvincrespo


1 Answers

I got success with this method. (added to a boilerplate plugin hence the MIT license comment is included)

See the use of @global + @class and the @global on the prototype. That seems to do it.

Code copied below: Enjoy & make it better please.

/**
* 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 );
like image 131
matt dales Avatar answered Aug 11 '26 08:08

matt dales