Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8375575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:12:46+00:00 2026-06-09T15:12:46+00:00

this.init = function (onupgradeneeded, onsuccess) { var openRequest = indexedDB.open(dbName); openRequest.onupgradeneeded = function (e)

  • 0
    this.init = function (onupgradeneeded, onsuccess) {

        var openRequest = indexedDB.open(dbName);

        openRequest.onupgradeneeded = function (e) {

            db = e.target.result;

            if (!db.objectStoreNames.contains(objectStoreName)) {

                console.log('Creating the ' + objectStoreName + ' objectstore');

                db.createObjectStore(objectStoreName, { keyPath: "id", autoIncrement: true });

            }

        };

        openRequest.onsuccess = function (e) {

            db = e.target.result;

            db.onerror = function (event) {
                // Generic error handler for all errors targeted at this database requests
                console.log("Database error: " + event.target.errorCode);
            };
        };

    };

Called by:

var idb = new Demo.IndexedDB();
idb.init();

When the init function runs, it will either end up in openRequest.onupgradeneeded or openRequest.onsuccess.

What i would like to know is if its possible to create a generic callback function that gets called in both function. So regardless of which of the two functions that runs i can know when theyre done by using

idb.init(function(){
    //onupgradeneeded or onsuccess completed
});

Hope you get the idea, otherwise ill elaborate.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:12:47+00:00Added an answer on June 9, 2026 at 3:12 pm

    Just pass in one callback function and call that one single callback in both cases:

    this.init = function (onFinish) {
    
        var openRequest = indexedDB.open(dbName);
    
        openRequest.onupgradeneeded = function (e) {
    
            db = e.target.result;
    
            if (!db.objectStoreNames.contains(objectStoreName)) {
    
                console.log('Creating the ' + objectStoreName + ' objectstore');
    
                db.createObjectStore(objectStoreName, { keyPath: "id", autoIncrement: true });
    
            }
            onFinish();
    
        };
    
        openRequest.onsuccess = function (e) {
    
            db = e.target.result;
    
            db.onerror = function (event) {
                // Generic error handler for all errors targeted at this database requests
                console.log("Database error: " + event.target.errorCode);
            };
            onFinish();
        };
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class: function RustEditor() { this.init = function() { var saveButton =
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I have this code: var obj = function (i) { this.a = i; this.init
Here is some code: var class = function(elem,div){ this.elem= elem; this.div = div; this.init
MyClass = function() { var init = function() { console.log(Initializing); } this.init(); } var
<script> (function() { $('html').addClass('js'); var contactForm = { container: $('#contact'), <-- THIS COMMA init:
function LolClass(){ this.init = function(){ button_a.bind(tap, function(){ this.refreshFields(); // doesn't work //refreshFields(); // doesn't
I have the following within an XHTML document: <script type=text/javascript id=JSBALLOONS> function() { this.init
I have this form submit code: Event.observe(window, 'load', init, false); function init() { Event.observe('addressForm',
I'm using Expressjs w/ node.js and I have a route like this: users.init(app.db, function()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.