I am a new CS graduate and work as an HTML5 web app developer. This form of development is new to me so pardon my incompetence on the topic... I have a javascript function that I want to return an object or change reference to the object passed, see below: NOTE: this reads all the values stored in the passed "table" within my indexed DB

function readAll(obj, table) {

var objectStore = db.transaction(table).objectStore(table);

objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;

if (cursor) {

obj.push({id: cursor.key, name: cursor.value.name, age: cursor.value.age, email: cursor.value.email});

cursor.continue();
}
else {
alert("No more entries!");
}
};
}

My original thought was to create the object in the above function and then return it. The problem here is that the elements are added to the object in the scope of the onsuccess function... so then I thought I could pass the object by reference to solve the issue which I like but I seem to be missing some key javascript insight because I cant figure out why the original object isn't being changed. I am interested in any solution, whether solving my pass by reference dilemma or showing me the right way to refactor this so that it can return the object.

Thanks,