5

如何记录混合或多重继承?

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

Parent.prototype.parentTest = 5;

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

Mixin.prototype.mixinTest = 5;

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

JsDoc有什么官方的吗?如果不是,那么你希望它怎么写?

4

2 回答 2

3

JsDoc@augments工具包实际上支持多个(我没有尝试过,但他们的单元测试建议如此,搜索“多个”)。

对于您可以使用@lendsand的 Mixins @borrows,请参阅此处的示例:http ://code.google.com/p/jsdoc-toolkit/wiki/CookBook

于 2011-01-30T17:41:38.847 回答
3

怎么样:

@mixin [<MixinName>]

添加到任何混入的对象:

@mixes <OtherObjectPath>

文档链接中提取:

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

于 2015-04-22T05:58:46.207 回答