English 中文(简体)
TelephoneGap and Javascript OOP
原标题:PhoneGap and Javascript OOP

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();
}

而主编是:

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);
    };

}

这是我目前掌握开始工作流程的守则。 问题在于,在主编Model.jsthis.database.transaction(Rologin.check Carloin, go Carlogin);它只得一 nothing。 当我改变这一行文时,行文记录仪的行文是行文,但 t变却未定。

我可能在这里做一些错误,但我不知道为什么。 Maybe Javagust OOP没有电话支持,我确实不相信。

你们能否帮助?

Thanks in advance,
Elkas

最佳回答

问题是,当你说<条码>这一条码时,你将提及 功能,但忽略了你希望与这一功能相联系的<>目标代码>。 这是 Java文的基本特性之一,你们必须完全理解,或者在与 Java文打交道时总是会混淆。

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.

。 从内部看,这种方法只是援引您的原始职能(作为贵物体的方法)的一种功能。

www.un.org/Depts/DGACM/index_spanish.htm 您将如何使用。

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

同样,你所说的话是“带网<编码>check Carloin至this.login。 并把它作为方法参照,而不是作为附带的职能。

(当然是,我发明了Function.prototype.bind。) 我在旧的一篇文章中描述了这种说法,即“通过部分申请在贾瓦特进行客观导向的活动”,它是第一批列入Proto型的公用事业之一,现在,在ECMA第5号文中它已经标准化。 为了作出更详细的解释,你可能会在某处挖掘该条。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签