简体   繁体   中英

jsDoc Toolkit methods, fields and properties don't show when I use a self var

Toolkit

I'm trying to document my classes but i'm using a "self" var to expose only the public methods.

jsDoc can find the class name, but can't find the methods, fields, properties, etc...

this is 1 of my classes:

Anny suggestion how I should approach this?

(function(App){
  /** @class The ViewModel for the EventView */
  App.ViewModels.EventsViewModel = function(service) {

    var self = {};

    /** Observable array containing events */
    self.events = new ko.observableArray();

    /** Call the fetchEvents method on the service */
    self.refreshEvents = function(e){
        $('.refreshBtn').changeIcon('refreshing');
        service.fetchEvents();
    }
    /** subscribe on the service->currentEvents var
      * on change update the events in this viewmodel
      * set the refesh butting is set to refresh (instead of refreashing) */
    service.currentEvents.subscribe(
        function(newValue){
            self.events(newValue);
            $('.refreshBtn').changeIcon('refresh');
        }
    );
    /** function for a timespan string ex: "10:00 - 14:00"
      * Date inputs should be of ISO-8601 Date format  */
    self.toTimeString= function(/* String */ start,/* String */ end)/* String */
    {
        var out = "";
        try
        {
            out =(start!=null && end!=null)? Util.IsoDateParse(start).format("HH:MM") + " - " + Util.IsoDateParse(end).format("HH:MM") : ""
        }
        catch(err)
        {
            out ="Error during toTimeString.\n\n";
            out+="Error description: " + err + "\n\n";
        }
        return out;
    }

    /** Call the fetchEvents method on the service */
    self.refreshEvents();

    return self;
  };
})(App)

ps: I'm using Knockoutjs & jQueryMobile

EDIT:

Thanks! Almost there... I tried to do something like this:

/** @memberOf App.ViewModels.EventsViewModel#
  * @field * @description Observable array containing events */
self.events = new ko.observableArray();

jsDoc shows it like "self.events" instead of "events"

Use the memberOf tag( TagMemberOf ). And since App.ViewModels.EventsViewModel is declared in an anonymous function you may need to use the name tag( TagName ) to scope it as global.

Edit:

Try:

/** @memberOf App.ViewModels.EventsViewModel#
  * @field
  * @description Observable array containing events
  * @name events
  */
self.events = new ko.observableArray();

It is a simple constructor. Use 'this' instead 'self'.

JsDoc understand members of 'this'

If you want to use other name than 'this', you can add alternative

var StackOverflow = function(){
  /** Alternative */
  var me = this;

  /**
  * Default rating
  * @type {number}
  */
  this.rating = 10;

  /** Load Happy New Year: increase rating */
  this.loadNewYear = function() {
    $.ajax().done(function(){
      me.rating = 100500;
    });
  };
};

PS: do not use 'self': https://stackoverflow.com/a/3216464/1197421

Use 'me' or something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM