Вопрос по javascript – Как документировать модуль Require.js (AMD) с помощью jsdoc 3 или jsdoc?

27

У меня есть 2 типа модулей:

Require.js Main File:

    require.config({
      baseUrl: "/another/path",
      paths: {
        "some": "some/v1.0"
      },
      waitSeconds: 15,
      locale: "fr-fr"
    });


    require( ["some/module", "my/module", "a.js", "b.js"],
      function(someModule,    myModule) {
      }
    );

Mediator Pattern:

define([], function(Mediator){

var channels = {};
if (!Mediator) Mediator = {};  

Mediator.subscribe = function (channel, subscription) {   
  if (!channels[channel]) channels[channel] = [];
   channels[channel].push(subscription);
};

Mediator.publish = function (channel) {
  if (!channels[channel]) return;
  var args = [].slice.call(arguments, 1);
  for (var i = 0, l = channels[channel].length; i < l; i++) {
    channels[channel][i].apply(this, args);
  }
};

return Mediator;

});

Как я могу документировать это с jsdoc3, когда это возможно с jsdoc тоже?

Ваш Ответ

5   ответов
16

This is my first answer on SO, please let me know how I can improve future answers.

Your specific example

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded@lendsError: User Rate Limit Exceeded@nameError: User Rate Limit Exceeded

 define([], /** @lends Mediator */ function(Mediator){
    /** 
     * Mediator class
     * This is the interface class for user related modules
     * @class Mediator
     */

    var channels = {};
    if (!Mediator) Mediator = {};  

    /**
      * .... description goes here ...
      * @function 
      *
      * @param {Number} channel  ..... 
      * @param {String} subscription ..............
      * @example
      * add the sample code here if relevent.
      * 
      */        
    Mediator.subscribe = function (channel, subscription) {   
      if (!channels[channel]) channels[channel] = [];
       channels[channel].push(subscription);
    };

    Mediator.publish = function (channel) {
      if (!channels[channel]) return;
      var args = [].slice.call(arguments, 1);
      for (var i = 0, l = channels[channel].length; i < l; i++) {
        channels[channel][i].apply(this, args);
      }
    };

return Mediator;

});

Error: User Rate Limit Exceeded@lendsError: User Rate Limit Exceeded@lendsError: User Rate Limit Exceededfunction(Mediator) {Error: User Rate Limit Exceeded@nameError: User Rate Limit Exceeded

Note: I've used the @exports tag at the same place as where I put the @lends tag. While that works, it'll create a module in the docs… and I only wanted to generate docs for the class. This way works for me!

General jsDoc references

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded trouble
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded@classError: User Rate Limit Exceeded@constructorError: User Rate Limit Exceeded@returnError: User Rate Limit Exceeded
@lendsError: User Rate Limit Exceeded.prototypeError: User Rate Limit Exceededusejsdoc.org/tags-lends.html
8

Error: User Rate Limit Exceededlink from Muxa's answerError: User Rate Limit Exceeded

The RequireJS library provides a define method that allows you to write a function to return a module object. Use the @exports tag to document that all the members of an object literal should be documented as members of a module.

Module Example

define('my/shirt', function () {
   /** 
    * A module representing a shirt.
    * @exports my/shirt
    * @version 1.0
    */
    var shirt = {

        /** A property of the module. */
        color: "black",

        /** @constructor */
        Turtleneck: function(size) {
            /** A property of the class. */
            this.size = size;
        }
    };

    return shirt;
});

Error: User Rate Limit Exceededmy/shirt moduleError: User Rate Limit ExceededcolorError: User Rate Limit ExceededTurtleneckError: User Rate Limit ExceededTurtleneckError: User Rate Limit Exceededsize.

Constructor Module Example

Use the @alias tag simplify documenting a constructor-module in RequireJS.

/** 
 * A module representing a jacket.
 * @module jacket
 */
define('jacket', function () {
    /**
     * @constructor
     * @alias module:jacket
     */
    var exports = function() {
    }

    /** Open and close your Jacket. */
    exports.prototype.zip = function() {
    }

    return exports;
});

Error: User Rate Limit Exceeded@lendsError: User Rate Limit Exceeded@module, @exportsError: User Rate Limit Exceeded@aliasError: User Rate Limit Exceededdocumentation referencing RequireJS.

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded@moduleError: User Rate Limit Exceededreturn { key: value, etc.};Error: User Rate Limit Exceededvar ModuleName = { key: value... };Error: User Rate Limit Exceeded@moduleError: User Rate Limit ExceededvarError: User Rate Limit ExceededdefineError: User Rate Limit Exceeded
0

Error: User Rate Limit Exceeded

Mediator as a module

/**
 * Mediator Module
 * @module Package/Mediator
 */
define([], function(Mediator){

  var channels = {};
  if (!Mediator) Mediator = {};  

  /**
   * Subscribe
   * @param  {String} channel Channel to listen to
   * @param  {Function} subscription Callback when channel updates
   * @memberOf module:Package/Mediator
   */
  Mediator.subscribe = function (channel, subscription) {   
    if (!channels[channel]) channels[channel] = [];
     channels[channel].push(subscription);
  };

  /**
   * Publish
   * @param  {String} channel  Channel that has new content
   * @memberOf module:Package/Mediator
   */
  Mediator.publish = function (channel) {
    if (!channels[channel]) return;
    var args = [].slice.call(arguments, 1);
    for (var i = 0, l = channels[channel].length; i < l; i++) {
      channels[channel][i].apply(this, args);
    }
  };

  return Mediator;

});

Error: User Rate Limit Exceeded

/**
 * Mediator Module
 * @module Package/Mediator
 */
define([], function(){

  var channels = {};
  var Mediator = {}

  ...

Error: User Rate Limit ExceededMediatorError: User Rate Limit ExceededMediatorError: User Rate Limit ExceededMediatorError: User Rate Limit Exceeded

2

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

/**
* @classdesc This class will be documented automatically because it is not in
* another function.
* @constructor
*/
function TestClassGlobal() {
/**
* This is a public method and will be documented automatically.
*/
this.publicMethod = function() {
};
}

Error: User Rate Limit ExceededglobalError: User Rate Limit Exceededmember of a namespace:

define([], fun,ction() {
/**
* @classdesc This won't be automatically documented unless you add memberof,
* because it's inside another function.
* @constructor
* @memberof Namespace
*/
function TestClassNamespace() {
}

/**
* @classdesc This won't be automatically documented unless you add global,
* because it's inside another function.
* @constructor
* @global
*/
function TestClassForcedGlobal() {
}
});
8

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

    define([], function(Mediator){
        /** 
         * Mediator class
         * This is the interface class for user related modules
         * @name Mediator
         * @class Mediator
         * @constructor
         * @return Session Object
         */

        var channels = {};
        if (!Mediator) Mediator = {};  

        /**
          * .... description goes here ...
          * @name Mediator#subscribe
          * @function 
          *
          * @param {Number} channel  ..... 
          * @param {String} subscription ..............
          * @example
          * add the sample code here if relevent.
          * 
          */        
        Mediator.subscribe = function (channel, subscription) {   
          if (!channels[channel]) channels[channel] = [];
           channels[channel].push(subscription);
        };

        Mediator.publish = function (channel) {
          if (!channels[channel]) return;
          var args = [].slice.call(arguments, 1);
          for (var i = 0, l = channels[channel].length; i < l; i++) {
            channels[channel][i].apply(this, args);
          }
        };

    return Mediator;

    });

Error: User Rate Limit Exceeded

Похожие вопросы