Skip to content

Use widget function from an other jquery widget

How can I use a custom widget function in a magento jquery widget?

requirejs-config.js

var config = {
    "map": {
        "*": {
            "customwidget": "Vendor_Module/js/customwidget",
            "Magento_Catalog/js/catalog-add-to-cart": "Vendor_Module/js/catalog-add-to-cart"
        }
    }
};

catalog-add-to-cart.js

    define([
        'jquery',
        'mage/translate',
        'underscore',
        'Magento_Catalog/js/product/view/product-ids-resolver',
        'Magento_Catalog/js/product/view/product-info-resolver',
        'Vendor_Module/js/customwidget',
        'jquery-ui-modules/widget'
    ], function ($, $t, _, idsResolver, productInfoResolver, customwidget) {
        'use strict';
    
        $.widget('mage.catalogAddToCart', {
    ...
    ...
    ...
        /**
         * @param {jQuery} form
         */
        ajaxSubmit: function (form) {
            var self = this,
                productIds = idsResolver(form),
                productInfo = self.options.productInfoResolver(form),
                formData;

customwidget.myFunction();
// Uncaught TypeError: customwidget.myFunction is not a function