Possible Duplicate:
JS Object this.method() breaks via jQuery
Hello,
I'm playing around with creating classes in javascript but I don't think I really understand everything.
Here is some (simplified) code I wrote (the .bind() comes from jQuery 1.4.1):
function MyClass(size)
{
this.myList = new Array(size);
for (var i = 0; i < size; i++)
{
this.myList[i] = "Test " + i;
}
}
MyClass.prototype.InitCells = function()
{
$('#grid tbody tr td').bind('click', this.GetValue);
}
MyClass.prototype.GetValue = function()
{
alert(this.myList[1]);
}
Then I do this in my HTML-file:
var test = new MyClass(10);
test.InitCells();
Then, when I click on one of the <td>
's, I get this error: 'this.myList is null or not an object'
What do I need to do to access myList in the GetValue method?