JSDoc 中文网

语法

🌐 Syntax

@mixin [<MixinName>]

概述

🌐 Overview

mixin 提供的功能旨在添加到其他对象中。如果需要,可以使用 @mixin 标签来表示一个对象是 mixin。然后,可以向使用该 mixin 的对象添加 @mixes 标签。

🌐 A mixin provides functionality that is intended to be added to other objects. If desired, you can use the @mixin tag to indicate that an object is a mixin. You can then add the @mixes tag to objects that use the mixin.

示例

🌐 Examples

使用 @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...
    }
};