Javascript 如何挂接jQuery小部件';s函数?

Javascript 如何挂接jQuery小部件';s函数?,javascript,jquery,jquery-ui,magento,widget,Javascript,Jquery,Jquery Ui,Magento,Widget,我有一个jQuery小部件(主题外:它来自Magento 2),它的功能如下: $.widget('custom.SwatchRendererTooltip', { // some more code here.... /** * Update total price * * @private */ _UpdatePrice: function () { var $widget = this,

我有一个jQuery小部件(主题外:它来自Magento 2),它的功能如下:

$.widget('custom.SwatchRendererTooltip', {
    // some more code here....

    /**
     * Update total price
     *
     * @private
     */
    _UpdatePrice: function () {
        var $widget = this,
            $product = $widget.element.parents($widget.options.selectorProduct),
            $productPrice = $product.find(this.options.selectorProductPrice),
            options = _.object(_.keys($widget.optionsMap), {}),
            result;

        $widget.element.find('.' + $widget.options.classes.attributeClass + '[option-selected]').each(function () {
            var attributeId = $(this).attr('attribute-id'),
                selectedOptionId = $(this).attr('option-selected');

            options[attributeId] = selectedOptionId;
        });

        result = $widget.options.jsonConfig.optionPrices[_.findKey($widget.options.jsonConfig.index, options)];

        $productPrice.trigger(
            'updatePrice',
            {
                'prices': $widget._getPrices(result, $productPrice.priceBox('option').prices)
            }
        );

    },
}

我想以某种方式钩住这个函数,或者至少想知道它何时被触发。因此,每当调用
\u UpdatePrice
时,我都想知道它,以便进行操作。这怎么可能呢?

该函数会触发一个事件
updatePrice
,您可以收听该事件:

$('body').on('updatePrice', function (e, data) {
  console.log(e.currentTarget, data.prices);
});