@use JSDoc

語法

@mixin [<MixinName>]

概述

Mixin 提供要新增至其他物件的功能。若需要,你可以使用 @mixin 標籤來指出物件是 Mixin。然後,你可以將 @mixes 標籤新增至使用 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...
    }
};