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 6624251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:37:46+00:00 2026-05-25T21:37:46+00:00

I’m starting with phonegap and also trying to apply JavaScript OOP with it. But

  • 0

I’m starting with phonegap and also trying to apply JavaScript OOP with it. But the problem are the method calls and stuff. imagine this:
I have a main controller in JavaScript, this file try to control most of the work-flow between network calls, database a change views.
This is my main.js.

var onlineStatus = false;
var mainModel;
var connectTo = "http://192.168.1.65/mobile/service/";

document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("online", online, false);
document.addEventListener("offLine", offline, false);

function whenOnline() {
    setOnline(true);
}

function whenOffline() {
    setOnline(false);
}

function onDeviceReady() {
    mainModel = new MainModel();
    mainModel.openDatabase();
    mainModel.startApplication();
}

and the mainModel is this:

function MainModel() {
    this.isOnline = false;
    this.database = null;
    this.login = null;

    this.getDatabase = function() {
        return this.database;
    };

    this.openDatabase = function() {
        this.login = new LoginModel();
        this.database = window.openDatabase("wayacross", "0.2", "Test DB", 1000000);
    };

    this.startApplication = function() {
        this.database.transaction(this.login.checkLogin, goLoggin);
    };
}

And the Login Model:

function LoginModel() {

    this.loginError = function() {
        navigator.notification.alert('Login Error', // message
        null, // callback
        'Login', // title
        'Done'                  // buttonName
        );
        goLogin();
    };

    this.isLogged = function(tx, results) {
        //ajax code
    };

    this.checkLogin = function(tx) {
        alert('checkLogin: Variable TX = '+ tx);
        tx.executeSql('SELECT * FROM login', [], this.isLogged, this.loginError);
    };

}

This is the code I have at the moment to control the start work-flow. The problem is when i call in mainModel.js this.database.transaction(this.login.checkLogin, goLoggin); it won’t do nothing. When I change this.login.checkLogin to this.login.checkLogin() it works but the tx variable go as undefined.

I’m probably doing something wrong here but I don’t know why. Maybe JavaScript OOP isn’t supported with phonegap, thing that I don’t truly believe.

Can you help?

Thanks in advance,
Elkas

  • 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-05-25T21:37:47+00:00Added an answer on May 25, 2026 at 9:37 pm

    The problem is that when you say this.login.checkLogin, you are getting a reference to the function but losing the reference to the object this.login which you want associated with the function. This is one of the fundamental properties of Javascript that you have to understand completely or you will always be confused when working with Javascript.

    This is exactly what Function.prototype.bind is for. It is not available natively in older browsers (so most Javascript frameworks have their own implementation), but since you’re using PhoneGap, you’re probably targeting a modern mobile WebKit browser.

    What Function.prototype.bind does is bundle a function and an object together into a self-contained “method reference”. Internally, a method reference is simply a function that invokes your original function as a method of your object.

    Here’s how you would use it:

    this.database.transaction(this.login.checkLogin.bind(this.login), goLoggin);
    

    Again, what you’re saying there is “bind checkLogin to this.login and give it back to me as a method reference, not just as a detached function”.

    (Coincidentally, I kind of invented Function.prototype.bind. I described it in an old article called “Object-Oriented Event Listening through Partial Application in Javascript”, it was one of the first utilities to be included in Prototype, and now it’s been standardized in ECMAScript 5. For a more detailed explanation, you could probably dig up that article somewhere.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is 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.