I got an object defined global way:
window.myobj = {};
Then new elements are being added and finally it is being saved via ajax to database by SaveData(obj) function. The problem is, that I am making it alot of times in short period, and it seems that what is being passed to function is only a pointer to one single object, so when another event occures, it changes inside a save function even when it was changed outside. In PHP, you have to use &$obj for it... so how do I do it properly, so the obj passed to the function would not be only a pointer?
Edit: The problem appeared in here:
Lets say that event = {time:123,type:blah}
function SaveData(event){
  obj = jQuery.extend({}, event); // doesn't seem to replicate event
  $.post('save',obj,function(res){
    if(res) console.log(obj);
  });
  if(obj.type == 'blah'){
     newobj = jQuery.extend({}, obj);
     newobj.type = 'newtype';
     newobj.time = 234;
     SaveData(newobj);
  }else if(obj.type == 'newtype'){
     newobj = jQuery.extend({}, obj);
     newobj.type = 'lasttype';
     newobj.time = 345;
     SaveData(newobj);  
  }
}
This returns 3 objects that are the same:
{time:345,type:lasttype}
 
     
    