我有一个对象。它有一些属性、一个 DOM 元素的初始化函数和一个用于该 DOM 元素的事件处理程序。
我希望我的事件处理程序能够访问对象的属性。我正在使用.bind(this),但它说“不能调用未定义的方法”bind”。我究竟做错了什么?
var SignUpForm2 = {
eForm: null,
eEmailInput: null,
ePasswordInput: null,
signUpURL: null,
email: null,
password: null,
handleFormSubmit: function() {
e.preventDefault();
this.email = this.eEmailInput.val();
this.password = this.ePasswordInput.val();
$.ajax({
type: "POST",
url: this.signUpURL,
data: {
email: this.email,
password: this.password
},
success: function(response){
}
});
},
init: function(eForm) {
this.eForm = eForm;
this.eEmailInput = this.eForm.find('input[name="email"]');
this.ePasswordInput = this.eForm.find('input[name="password"]');
this.signUpURL = "/index.php/ajax/user-sign-up-via-email";
this.eForm.submit(this.handleFormSubmit.bind(this));
},
}