Possible Duplicate:
“this” keyword in event methods when using JavaScript prototype object
I have created a class called MyClass
in Javascript and bound the onclick
event to a button on the page. When the onclick
event fires I want to call another member function but it gives me undefined error. please help.
//MyClass constructor
MyClass = function() {
//Find search button
this.ctrlSearchButton = $("#btnSearch");
//Attach onclick event to search button
this.ctrlSearchButton.click(this.onSearchButtonClick);
};
MyClass.prototype.onSearchButtonClick = function () {
DoSearch();// ERROR : Object Expected
};
MyClass.prototype.DoSearch = function () {
alert("search called");
};