javascript 覆盖 class 变量

javascript override class variable

我有 class 变量,我想通过外部文件中的另一个函数更改变量值

Class代码

frappe.ui.Notifications = class Notifications {
    constructor() {
        frappe.model
            .with_doc('Notification Settings', frappe.session.user)
            .then(doc => {
                this.notifications_settings = doc;
                this.make();
            });
    }

    make() {
        this.$dropdown = $('.navbar').find('.dropdown-notifications');
        this.$dropdown_list = this.$dropdown.find('.notifications-list');
        this.$notification_indicator = this.$dropdown.find('.notifications-indicator');
    }
};

我魔杖改变变量this.$dropdown

frappe.ui.Notifications.$dropdown =  $('.Header').find('.dropdown-item-notifications');

通知 class 实例设置在 frappe.frappe_toolbar.notifications。您可以使用它来覆盖 属性.

frappe.frappe_toolbar.notifications.$dropdown = $('.Header').find('.dropdown-item-notifications');