JSDoc 中文网

语法

🌐 Syntax

@mixes <OtherObjectPath>

概述

🌐 Overview

@mixes 标签表示当前对象混入了来自 OtherObjectPath 的所有成员,OtherObjectPath 是一个 @mixin

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

示例

🌐 Examples

首先,我们使用 @mixin 标签记录一个混入:

🌐 To start, we document a mixin with the @mixin tag:

“@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 函数。

🌐 Now we add a FormButton class and call a "mix" function that mixes all of the Eventful functions into FormButton, so that FormButton can also fire events and have listeners. We use the @mixes tag to indicate that FormButton mixes the Eventful functions.

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