2011-01-30 8 views
5

Jak udokumentować mixiny lub dziedziczenie wielokrotne?Jak JsDoc wiele dziedziczenia lub mixins?

/** 
* @class Parent 
*/ 
function Parent() { 
} 

Parent.prototype.parentTest = 5; 

/** 
* @class Mixin 
*/ 
function Mixin() { 
} 

Mixin.prototype.mixinTest = 5; 

/** 
* @class Child 
* @augments Parent 
* @mixin Mixin 
*/ 
function Child() { 
} 

Czy jest coś oficjalnego z JsDoc? Jeśli nie, to jak byś chciał, żeby to było napisane?

+0

unikać wielokrotnego dziedziczenia, jeśli to możliwe. Może stać się naprawdę brudny. Głównie dla opiekuna. – Raynos

+5

Mieszanki są przydatne. Są jak dodatkowy zestaw narzędzi, który możesz zabrać ze sobą wszędzie. Używane są w ExtJS 4 i Dojo szeroko. – Tower

Odpowiedz

1

Jak o:

@mixin [<MixinName>] 

Dodaj do wszelkich obiektów, które mieszają się:

@mixes <OtherObjectPath> 

Wyciągnięty z documentation link:

/** 
 
* 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... 
 
    } 
 
}; 
 

 

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