1

I am looking to update the value in a chaseObj from the method in another object. Please Advise, Thank you!

var s, searchUts;
var getValue = '';
var generateObject = function() {
  var chaseObj = {
    "timeFilters" : getValue
  };
  return chaseObj;
};

searchUts = s = {
  createValue: function() {
    var x = 10;
    var y = 20;
    getValue = x + y; //append this value to chaseObj inside the generateObject
  },
  postToBackEnd: function() {
  var chaseObj = generateObj();
    $.ajax({
    url: localhost:8080/site/home,
    data:JSON.stringify(chaseObj) //chaseObj is not updated with new value here

    })
  }

};
6
  • You could make timeFilters a getter function. Commented Oct 26, 2017 at 2:55
  • since it's un-reachable though code, you can't. you can pass an object around to keep the refs instead of mere string values, or use a method + closure. Commented Oct 26, 2017 at 2:55
  • yes there was a typo Commented Oct 26, 2017 at 2:57
  • Didn't get you @dandavis Commented Oct 26, 2017 at 2:58
  • can you please advise a snippet @4castle Commented Oct 26, 2017 at 2:58

1 Answer 1

2

Unclear what you want but is this the result you wanted?

var s, searchUts;
var getValue = '';
var generateObject = function() {
  var chaseObj = {
    "timeFilters" : getValue
  };
  return chaseObj;
};

searchUts = s = {
  createValue: function(obj) {
    var x = 10;
    var y = 20;
    obj.timeFilters = x + y; //append this value to chaseObj inside the generateObject
  },
  postToBackEnd: function() {
     var chaseObj = generateObject();
     this.createValue(chaseObj);
     console.log(JSON.stringify(chaseObj));
  }
};

s.postToBackEnd();

Sign up to request clarification or add additional context in comments.

1 Comment

great job! but unfortunately at my end I have multiple params to createValue method and if I use this code, its not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.