最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to JsDoc multiple inheritance or mixins? - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Jan 30, 2011 at 14:54 TowerTower 103k131 gold badges364 silver badges521 bronze badges 2
  • Avoid multiple inheritance if possible. It can get really messy. Mainly for the maintainer. – Raynos Commented Jan 30, 2011 at 14:59
  • 5 Mixins are useful. They are like extra toolset that you can bring anywhere. They are used in ExtJS 4 and Dojo extensively. – Tower Commented Jan 30, 2011 at 15:16
Add a ment  | 

2 Answers 2

Reset to default 4

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);

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./p/jsdoc-toolkit/wiki/CookBook

发布评论

评论列表(0)

  1. 暂无评论