I want to create a PhoneGap-Application with multiple database tables that will be parsed into Javascript-Objects, so I wrote the following code.
$(document).ready( function(){
var startpage = Object.create(Persons);
startpage.load();
});
var Page = {
db: window.openDatabase("database", "1.0", "My Database", 200000),
load: function(){
this.db.transaction(this.queryDB, this.errorCB);
},
errorCB: function(err){
alert("Error processing SQL: " + err.message);
}
}
var Persons = Object.create(Page, {
queryDB: {
value: function(tx){
tx.executeSql(
'SELECT * FROM PERSONS',
[],
this.createObjects, <-- Problem is here
this.errorCB
);
}
},
createObjects: {
value: function(tx, results){
// [...] parse results to objects
}
}
});
The problem is that "this" in the queryDB-method is a reference to the method itself not to the Object. Does anyone know how I can reference the right method?
Thank you!