首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法覆盖converse.js核心函数

无法覆盖converse.js核心函数
EN

Stack Overflow用户
提问于 2016-02-29 12:15:31
回答 1查看 567关注 0票数 0

当试图重写converse.js核心函数时,我遇到了问题。下面的示例是:https://conversejs.org/docs/html/development.html#writing-a-converse-js-pluginhttps://conversejs.org/docs/html/quickstart.html。我的代码如下所示:

代码语言:javascript
复制
require(['converse'], function (converse) {
    "use strict";

    converse.plugins.add('pluginName', {
        overrides: {
            onConnected: function () {
                this._super.onConnected();
            },
            ChatBoxView: {                
                showMessage: function (attrs) {                    
                    this._super.showMessage(attrs);
                }
            }
        }
    });

    converse.initialize({
        bosh_service_url: 'http://myurl.com/http-bind/',
        i18n: locales.en,
        show_controlbox_by_default: true,
        roster_groups: true,
        keepalive: true,
        jid: 'admin@myurl.com',
        message_carbons: true,
        play_sounds: true,
        anonymous: false,
        allow_logout: false,
        authentication: 'prebind',
        prebind_url: '/prebind',
        auto_list_rooms: true
    });
});

此代码部分工作。聊天是显示的,它是连接的(this._super.onConnected();工作正常),但是当我想显示消息(ChatBoxView.showMessage函数)时会出错。错误消息是:TypeError: this.$是未定义的。

如何“定义”ChatBoxView这个方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-29 13:34:58

这个问题很可能是超级函数中的the变量绑定到错误的上下文中。

您可以通过将this._super.showMessage(attrs);更改为this._super.showMessage.apply(this, arguments);来解决这个问题。

它将使用正确的this参数和传递给重写函数的所有参数调用函数。

在sidenote上,我将更新文档以反映这一点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35699318

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档