This is kind of strange. I am sure I am missing some basic concept of programming but not sure whats that. Because till now I have never faced this issue.
Let me explain my issue through programming:
var result = {abc: 10, cde: 20, efg: 30};
var final_result = {};
var customFunction1 = function(results){
console.log(results);
return results; // result= {abc: 10, cde: 20, efg: 30}
};
var customFunction2 = function(results){
results.cde = 100;
results.efg = 500;
return results; // {abc: 10, cde: 100, efg: 500}
};
final_result.result1 = customFunction1(result);
final_result.result2 = customFunction2(result);
console.log(final_result);
In above program, I am passing result as parameter to function, and storing the return value of it in "final_result.result1". But this gets overwritten when I call a different function with same params. The output what I am getting is:
{"result1":{"abc":10,"cde":100,"efg":500},"result2":{"abc":10,"cde":100,"efg":500}}
Expected o/p is: {"result1":{"abc":10,"cde":20,"efg":30},"result2":{"abc":10,"cde":100,"efg":500}}
Why value of final_result.result1 gets overwritten by result.result2.
JSBin http://jsbin.com/mepizecuka/edit?js,console
Plunkr http://plnkr.co/edit/BF0UNnacV9UeXtyk3stI?p=preview
Can anyone please help me here.