So, I am learning Javascript while playing white Google Calendar APIs and I just can't figure how this piece of code is working this way:
var entriesResult = [];
var data = new Date(2010,3,22,17,0,0);
var callback = function(result) {
var entries = result.feed.getEntries();
if (entries.length != 0) {
entriesResult = eventsManager(entries, 0, data);
window.alert("inner entriesResult " + entriesResult.length);
}
}
this.service.getEventsFeed(this.query, callback, handleGDError);
window.alert("outer entriesResult " + entriesResult.length);
eventsManager() is a function that returns an array of Objects.
getEventsFeed() it's an API function: it queries the service and pass a "feed root" (a feed with selected items) to the callback function.
Why the first alert (inner..) outputs a valid entriesResult.length while the second one (outer..) always outputs a 0?
I tought javascript arrays are always passed by reference, what's wrong whit my code?
Thank you :)