Spec-Zone.ru › JSDoc

@mixes

Содержание

  • Синтаксис
  • Обзор
  • Примеры
  • Связанные ссылки

Синтаксис

@mixes <OtherObjectPath>

Обзор

Тег @mixes указывает, что текущий объект объединяет все члены из OtherObjectPath, что является @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.

Использование тега @mixes
/**
 * @constructor FormButton
 * @mixes Eventful
 */
var FormButton = function() {
    // code...
};
FormButton.prototype.press = function() {
  this.fire('press', {});
}
mix(Eventful).into(FormButton.prototype);

Связанные ссылки

  • @borrows
  • @class
  • @mixin

© 2011–2017 the contributors to the JSDoc 3 documentation project
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://jsdoc.app/tags-mixes.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API