So I wanted write something similar to this snipped from IndexedDB docs:
var req;
var store = getStore();
req = store.count();
req.onsuccess = function(evt) {
console.log("success: " + evt.result);
};
req.onerror = function(evt) {
console.error("add error", this.error);
};
https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
And started to wonder why javascript allow definitions of (deferred?) callbacks after a call and why it doesn't cause race conditions? Can someone share some light please?
So, how does javascript make sure that async call doesn't get executed before callback is assigned?
Thanks!