Ask about the use of indexedDB! ! ! ! !

  node.js, question
(function(){
 
 function IndexedDB(){
 //check browser support for indexedDB and web sql
 this.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB || false;
 // IDBKeyRange defines the range of keys
 this.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.mozIDBKeyRange || window.msIDBKeyRange || false;
 this.webSQLSupport = ('openDatebase' in window);
 this.db = null;
 
 this.init();
 bracket
 IndexedDB.prototype = {
 init : function(){
 var _this = this;
 
 _this.openDB();
 _this.insertData();
 },
 openDB : function(){
 var _this = this, request;
 
 //Open the database
 request = indexedDB.open("MyTestDatabase");
 //callback function after database is opened
 request.onsuccess = function(){
 _this.db = request.result;
 console.log(_this.db);
 };
 request.onerror = function(){
 alert("Why didn't you allow my web app to use IndexedDB?  !  ");
 };
 },
 insertData : function(data){
 var _this = this;
 console.log(_this.db);
 bracket
 };
 
 window.addEventListener('load', function(){
 new IndexedDB();
 }, false);
 
 })();

The code is as above. In the onsuccess callback in the openDB method, I have already obtained the operation object of the database and assigned it to this.db.
But why is this.db output in the insertData method null? It seems that it can only be implemented in other callbacks. I am not very clear about this mechanism. Please give me some popular science. Thank you!

Because onsuccess is an asynchronous callback, when you execute openDB, it is not immediately executed to onsuccess, and then you immediately execute insertData. at this time, onsuccess is not executed, so this.db is null