我有這個代碼是我的用戶類的一部分。當我調用這個函數:'這'不起作用在我的班級功能
user = new User();
user.regUser("john", "[email protected]", "john123", function() { });
我得到的錯誤
Uncaught TypeError: Object #<Database> has no method 'writeDb'
在用戶類的功能:
User.prototype.regUser = function(name, email, password, cb) {
this.db.exec("SELECT * from users WHERE user_email='"+email+"';", function(results) {
var len = results.rows.length;
if (typeof(cb) == 'function') {
if (len < 1) {
this.name = name;
this.email = email;
this.password = password;
this.writeDb();
cb(true); // username doesn't exists
} else {
cb(false); // username already exists
}
}
});
}
是問題也許是,「這個」變量被稱爲在我的函數的嵌套函數?因爲在其他功能是不嵌套時的作品。我怎樣才能解決這個問題?
- 小編輯: 我寫this.db.writeDb(),它必須是this.writeDb() 仍然得到錯誤,但。
offtopic:你不想執行這些查詢serverside,你?????? – Christoph
不,我正在使用webSQL,爲什麼? –
我認爲Christof指的是''SELECT * from users WHERE user_email ='「+ email +」'「''[易受SQL注入攻擊](http://xkcd.com/327/)。 –