Skip to content

Call this._super() from anonymous function in js mixin

I have made a mixin for the minicart. I want to execute an async call before the parent function should be called. However it doesn’t seem possible to call this._super() from an anonymous function. I tried to assign this to self but that doesn’t help.

Uncaught (in promise) TypeError: self._super is not a function

Can someone help me to get the right result?

var config = {
    config: {
        mixins: {
            'Magento_Checkout/js/sidebar': {
                'Vendor_Module/js/checkout-sidebar-mixin': true
            },
        }
    }
};

And the mixin

define([
    'jquery',
    'uiComponent'
], function ($, Component) {
    'use strict';
    return function (target) {
        return $.widget('mage.sidebar', $.mage.sidebar, {
            _removeItem: function (elem) {
                const self = this;
                asyncFunction().then(() => {
                    self._super(elem);
                });
            },

        });
    }
});