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

  • Home
  • SEARCH
  • 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 9211921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:24:24+00:00 2026-06-18T01:24:24+00:00

Although I searched for a solution, i did not found one for my problem.

  • 0

Although I searched for a solution, i did not found one for my problem. Im using cordova and jquery mobile. there are fired to events: document.ready and the device ready of cordova. i want to check the loading states by checking to booleans, to know when to start the main application.

so have a look at my code:

First: The first js-File loaded:

function checkReadyStates() {
    if(domReady && cordovaReady) {
        timer.stop();
        start();
    }
}

var domReady = false;
var cordovaReady = true;
var timer = new TimerModel({interval : 50, method : checkReadyStates});
timer.start();

// get notified when DOM is loaded
$(document).ready(function() {
    ConsoleController.info('Document ready.');
    domReady = true;
});

// get notified when cordova is ready
document.addEventListener('deviceready', function() {
    ConsoleController.info('Cordova loaded.');
    cordovaReady = true;
}, false);

Second: The TimerModel:

define(['backbone'],function(Backbone) {

var model = Backbone.Model.extend({

    defaults: {
        timerObject : null,
        active : false,
        interval : 1000,
        method : null,
    },

    // init timer
    initialize : function() {
        _.bindAll(this, 'start', 'stop'); // context bindings
    },

    // starts the timer with given interval
    start : function() {
        if(!this.active) {
            this.active = true;
            this.timerObject = setInterval(this.method, this.interval);
        }
    },

    // stops timer
    stop : function() {
        this.active = false;
        clearInterval(this.timerObject);
    }

});

// return the timer model
return model;

});

Hope someone’s able to help. 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-18T01:24:25+00:00Added an answer on June 18, 2026 at 1:24 am

    On this line of code here

    this.timerObject = setInterval(this.method, this.interval);
    

    Both this.method and this.interval are undefined, so you’re setting nothing running never. The reason for this is that Backbone.Model doesn’t define the properties passed in the constructor on the instance itself, but in an internal property called attributes. You can access the attributes using the model.get(property) method:

    this.timerObject = setInterval(this.get('method'), this.get('interval'));
    

    Furthermore it doesn’t really make sense to define the timer as a model. No doubt you’ll get it to work, but it’s not what Backbone.Modelis intended for. Models are used to represent a piece of data, not functionality. I think a simple function would serve you better here.

    Edit: To rephrase, models are not just for data, but they should contain data. The model is a good place to define functions (methods) that operate on that data. Your TimerModel on the other hand is pure logic – it doesn’t represent or encapsulate any data or state. I feel that logic is better encapsulated as a simple function “class”:

    var Timer = function(options) {
        options = options || {};
        this.active = false;
        this.interval = options.interval || 1000;
        this.method = options.method || null;
    
    
        // starts the timer with given interval
        this.start = function() {
            if(!this.active) {
                this.active = true;
                this.timerObject = setInterval(this.method, this.interval);
            }
        };
    
        // stops timer
        this.stop = function() {
            this.active = false;
            clearInterval(this.timerObject);
        };
    
        _.bindAll(this, 'start', 'stop')
    });
    

    Usage:

    var timer = new Timer({interval: 50, method:checkReadyStates});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

although I searched through existing threads for my problem I havent found a solution
I've searched around but can't find a solution to this problem. I'm using the
Although I have found some solutions to this problem, none of them refer to
Not sure how to work this but I found a way that works although
I searched the web and I searched stackoverflow up and down. No solution. Although
The view 'Art' or its master was not found. The following locations were searched
Although I've searched the Board and used google, I didn't get any useful results.
I looked and searched and couldn't find what I needed although I think it
Although appengine already is schema-less, there still need to define the entities that needed
I have an exceptionally bad CSV file. Although I solved the problem in the

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.