下記のソースコードで質問があります。
javascript
1// https://github.com/SuyashMShepHertz/indexedDB_sample/blob/master/index.html 2$(document).ready(function(){ 3 window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; 4 5 var request, db; 6 7 if(!window.indexedDB) 8 { 9 console.log("Your Browser does not support IndexedDB"); 10 } 11 else 12 { 13 request = window.indexedDB.open("testDB", 2); 14 request.onerror = function(event){ 15 console.log("Error opening DB", event); 16 } 17 request.onupgradeneeded = function(event){ 18 console.log("Upgrading"); 19 db = event.target.result; 20 var objectStore = db.createObjectStore("students", { keyPath : "rollNo" }); 21 }; 22 request.onsuccess = function(event){ 23 console.log("Success opening DB"); 24 db = event.target.result; 25 } 26 } 27});
request.on~
はイベントハンドラを設定していて、requestの取得はindexedDB.open()
で行っていると思います。requestの取得の後にイベントハンドラを設定しているのに、イベントハンドラが実行されるのでしょうか?request取得時にはまだイベントハンドラが未定義のため、何も実行されないと思います。
もしくは、requestにイベントハンドラを設定した場合にイベントが発火されるという形なのでしょうか?
ご回答、よろしくお願い致します。
あなたの回答
tips
プレビュー