Things to be noticed in extending a private function

Description : The things we need to notice when we are extending a private function

Scenario : For example we need to extend this function from the source code

 private confirmConsent(): void {

    const consentMessage = this.formModel.get(‘customerconsent’);

    const approveConsentView = new GlobalViewsConfirmationView({

      callBack: (): void => {

        this.formModel.set(‘consent’, true);

        const promise = this.formModel.save();

        if (promise) {

          promise.then(

            (): void => {

              this.options.collection.fetch().then(

                (): void => {

                  if (!this.options.inModal && !this.options.noRedirect) {

                    Backbone.history.navigate(‘#ach’, {

                      trigger: true

                    });

                  }

                }

              );

            }

          );

        }

      },

      title: Utils.translate(‘Approve Consent’),

      body: Utils.translate(consentMessage),

      autohide: true

    });

    approveConsentView.once(‘destroy’, () => {

      if (!!this.formModel.get(‘consent’) === false) {

        this.options.collection.trigger(‘noconsent’, this.options.collection);

 

      }

    });

    return this.application.getLayout().showInModal(approveConsentView, {});

  }

This function is from “PaymentInstrumentACHEditFormView”. So we need to assign a variable first like below

var ACHEditFormViews = PaymentInstrumentACHEditFormView.PaymentInstrumentACHEditFormView;

The function can be used like this manner below

var ACHEditFormViews = PaymentInstrumentACHEditFormView.PaymentInstrumentACHEditFormView;

        _.extend(ACHEditFormViews.prototype, {

          confirmConsent: _.wrap(ACHEditFormViews.prototype.confirmConsent, function (fn) {

  })

 });

Leave a comment

Your email address will not be published. Required fields are marked *