2011-01-30 15 views
5

¿Cómo se documentan las mezclas o la herencia múltiple?cómo JsDoc herencia múltiple o 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() { 
} 

¿Hay algo oficial de JsDoc? Si no, ¿cómo prefiere que se escriba?

+0

Evitar la herencia múltiple si es posible. Puede ser realmente complicado. Principalmente para el mantenedor. – Raynos

+5

Mixins son útiles. Son como herramientas adicionales que puedes llevar a cualquier parte. Se usan ampliamente en ExtJS 4 y Dojo. – Tower

Respuesta

1

Cómo sobre: ​​

@mixin [<MixinName>] 

Añadir a cualquier objeto que se confunden en:

@mixes <OtherObjectPath> 

sacado de 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);