JSDoc中文文档(@use JSDoc)

JSDoc @mixes 标签

目录

语法

@mixes <OtherObjectPath>

概述

The @mixes tag indicates that the current object mixes in all the members from OtherObjectPath, which is a @mixin.

@mixes标签指示当前对象混入了OtherObjectPath对象的所有成员,被混入的对象就是一个@mixin

示例

首先,我们用@mixin标签描述一个混入:

示例: 使用 @mixin
/**
 * 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...
    }
};

现在,我们添加一个FormButton类,并且调用"mix"函数,将Eventful的所有功能混入到FormButton,这样FormButton也可以触发事件和监听了。我们使用@mixes标签,以表明FormButton混入了Eventful的功能。

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