如何实现 JsDoc 多重继承或 mixins?

发布于 2024-10-15 03:38:02 字数 328 浏览 4 评论 0原文

如何记录 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() {
}

JsDoc 有官方消息吗?如果不是,那么您希望如何写?

How do I document mixins or multiple inheritance?

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

Parent.prototype.parentTest = 5;

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

Mixin.prototype.mixinTest = 5;

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

Is there anything official from JsDoc? If not then how would you prefer it to be written?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

起风了 2024-10-22 03:38:02

怎么样:

@mixin [<MixinName>]

添加到混合到的任何对象中:

@mixes <OtherObjectPath>

文档链接中提取:

/**
 * 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);

How about:

@mixin [<MixinName>]

Add to any objects that get mixed into:

@mixes <OtherObjectPath>

Pulled from 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);

氛圍 2024-10-22 03:38:02

JsDoc Toolkit 实际上支持多个 @augments (我没有尝试过,但是它们的 单元测试 建议如此,搜索“多个”)。

对于 Mixins,您可以使用 @lends@borrows,请参阅此处的示例:http://code.google.com/p/jsdoc-toolkit/wiki/CookBook

Multiple @augments are actually supported by the JsDoc Toolkit (I haven't tried, but their unit tests suggest so, search for "multiple").

For Mixins you can make use of @lends and @borrows, see the examples here: http://code.google.com/p/jsdoc-toolkit/wiki/CookBook

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文