How to JsDoc multiple inheritance or mixins?

妖精的绣舞 提交于 2019-12-12 11:06:10

问题


How do I document mixins or multiple inheritance?

/**
 * @class Parent
 */
function Parent() {
}

Parent.prototype.parentTest = 5;

/**
 * @class Mixin
 */
function Mixin() {
}

Mixin.prototype.mixinTest = 5;

/**
 * @class Child
 * @augments Parent
 * @mixin Mixin
 */
function Child() {
}

Is there anything official from JsDoc? If not then how would you prefer it to be written?


回答1:


Multiple @augments are actually supported by the JsDoc Toolkit (I haven't tried, but their unit tests suggest so, search for "multiple").

For Mixins you can make use of @lends and @borrows, see the examples here: http://code.google.com/p/jsdoc-toolkit/wiki/CookBook




回答2:


How about:

@mixin [<MixinName>]

Add to any objects that get mixed into:

@mixes <OtherObjectPath>

Pulled from documentation link:

/**
 * This provides methods used for event handling. It's not meant to
 * be used directly.
 *
 * @mixin
 */
var Eventful = {
    /**
     * Register a handler function to be called whenever this event is fired.
     * @param {string} eventName - Name of the event.
     * @param {function(Object)} handler - The handler to call.
     */
    on: function(eventName, handler) {
        // code...
    },

    /**
     * Fire an event, causing all handlers for that event name to run.
     * @param {string} eventName - Name of the event.
     * @param {Object} eventData - The data provided to each handler.
     */
    fire: function(eventName, eventData) {
        // code...
    }
};


/**
 * @constructor FormButton
 * @mixes Eventful
 */
var FormButton = function() {
    // code...
};
FormButton.prototype.press = function() {
  this.fire('press', {});
}
mix(Eventful).into(FormButton.prototype);


来源:https://stackoverflow.com/questions/4843528/how-to-jsdoc-multiple-inheritance-or-mixins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!