So im trying to build a music player using javascript. I created a DAO file for interacting with Web Database using this code:
function MusicDAO()
{
this.ins = openDatabase('musicDB', '1.0', 'MusicDB', 100 * 1024 * 1024);
this.lastQueryResults = null;
this.lastQueryError = null;
this.openMainTable();
this.openMainTable = function()
{
return this.execute("CREATE TABLE IF NOT EXISTS m_songs (file_id AUTO_INCREMENT, name, location, pic, genre)");
};
this.execute = function(query)
{
var instance = this;
instance.ins.transaction(function(tx){
tx.executeSql(query, [], function(e, results){
instance.lastQueryResults = results;
});
}, function(e){
console.log("error", e);
instance.lastQueryError = e;
});
return instance.lastQueryResults;
};
this.addSong = function(){
return this.execute("INSERT INTO m_songs" +
"(name, location, pic, genre)" +
"VALUES" +
"('menahem', '/pla', null, 'trance')");
};
}
and chrome keep shouting about this:
Uncaught TypeError: Object #<MusicDAO> has no method 'openMainTable'
and im a bit confused.. i cant call a function before the creation inside a function?