2011-01-30 4 views
5

Tôi làm cách nào để ghi lại các kết hợp hoặc đa thừa kế?Làm thế nào để JsDoc nhiều thừa kế hoặc mixin?

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

Parent.prototype.parentTest = 5; 

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

Mixin.prototype.mixinTest = 5; 

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

Có điều gì chính thức từ JsDoc không? Nếu không thì làm thế nào bạn muốn nó được viết?

+0

Tránh đa kế thừa nếu có thể. Nó có thể thực sự lộn xộn. Chủ yếu cho người bảo trì. – Raynos

+5

Mixins rất hữu ích. Chúng giống như các bộ công cụ bổ sung mà bạn có thể mang đến bất cứ đâu. Chúng được sử dụng rộng rãi trong ExtJS 4 và Dojo. – Tower

Trả lời

1

Làm thế nào về:

@mixin [<MixinName>] 

Thêm vào bất kỳ đối tượng mà có được trộn vào:

@mixes <OtherObjectPath> 

Đã kéo từ 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);