Use value returned from a function in another function

Hello,

I am new to backbone. Can anyone please explain how to use the value returned by one function in another function?

This is the pseudo code :

({
extendsFrom: 'RecordView',

initialize: function(options) {
this._super('initialize', [options]);
this.context.on('button:get_tax:click', this.get_tax, this);
this.model.addValidationTask('addressValidation', _.bind(this.save_button, this));


},


save_button: function(fields, errors, callback) {

use the value of 'currentTax' variable
},

get_tax: function() {

var currentTax = this.model.get('taxrate_name');
return currentTax;

}
})

Thank you

Parents
  • Hi Sarika Tandale,

    You can use a class level variable to store such value or a call function inside the other.

    Kind Regards,
    Rolustech Support
    Email: support@rolustech.com
    Website: www.rolustech.com

  • Hi Sarika Tandale

    just following on the response from Rolustech Support  

    I would recommend calling the get_tax function from your save_button function. I've added an example of what I mean below inside your save_button function

    ({
          extendsFrom: 'RecordView',

          initialize: function(options) {
                this._super('initialize', [options]);
                this.context.on('button:get_tax:click', this.get_tax, this);
                this.model.addValidationTask('addressValidation', _.bind(this.save_button, this));
            },


             save_button: function(fields, errors, callback) {

                   //use the value of 'currentTax' variable 

                  //get_tax belongs to the same object as save_button and thus you can refer to it via "this"

                  var currentTaxCopy = this.get_tax();

             },

             get_tax: function() {

                var currentTax = this.model.get('taxrate_name');
                return currentTax;

             }
    })

    Hope that helps

Reply
  • Hi Sarika Tandale

    just following on the response from Rolustech Support  

    I would recommend calling the get_tax function from your save_button function. I've added an example of what I mean below inside your save_button function

    ({
          extendsFrom: 'RecordView',

          initialize: function(options) {
                this._super('initialize', [options]);
                this.context.on('button:get_tax:click', this.get_tax, this);
                this.model.addValidationTask('addressValidation', _.bind(this.save_button, this));
            },


             save_button: function(fields, errors, callback) {

                   //use the value of 'currentTax' variable 

                  //get_tax belongs to the same object as save_button and thus you can refer to it via "this"

                  var currentTaxCopy = this.get_tax();

             },

             get_tax: function() {

                var currentTax = this.model.get('taxrate_name');
                return currentTax;

             }
    })

    Hope that helps

Children