javascript oop

I got a class named Table that encapsulate some table handling.
Below are two of it's methods.

Why do the alert report "object HTMLTableRowElement" instead of "object object". Shouldnt "this" contain a reference to the Table class?


Table.prototype.modifiers = function(event)
{
if (!event)
event = window.event;
this.mShiftKey = event.shiftKey;
this.mCtrlKey = event.ctrlKey;
alert(this);
}
Table.prototype.display = function (table)
{
this.mParentTable = table;
for (var i = 1; i < this.mRows.length; ++i)
{
var row = table.insertRow(i);
var method = this.SelectRows;
row.onclick = mouseDown(row);
row.onmousedown = this.modifiers;

var cell = null;
for (var j = 0; j < this.mRows[i].length; ++j)
{
cell = row.insertCell(j);
cell.textContent = this.mRows[i][j];

// ThreadId
if (j == 2)
cell.style.color = this.addThread(this.mRows[i][j]);
}

//row.cells[1].style.border = '1px solid';
if (i % 5 == 0)
row.className = 'fifthRow';
}
}
[1187 byte] By [verifier] at [2007-11-20 1:21:06]
# 1 Re: javascript oop
If this is not included in the object events, it will automatically default to the window, not to the element being referenced.
PeejAvery at 2007-11-8 0:41:00 >
# 2 Re: javascript oop
how should I do then?
I want to catch mouse events for a table row and let the event trigger a member function of the class Table.
verifier at 2007-11-8 0:41:58 >
# 3 Re: javascript oop
You have 5 different mouse events you can use within the tags.

onmousedown() (http://www.w3schools.com/jsref/jsref_onmousedown.asp)
onmousemove() (http://www.w3schools.com/jsref/jsref_onmousemove.asp)
onmouseout() (http://www.w3schools.com/jsref/jsref_onmouseout.asp)
onmouseover() (http://www.w3schools.com/jsref/jsref_onmouseover.asp)
onmouseup() (http://www.w3schools.com/jsref/jsref_onmouseup.asp)
PeejAvery at 2007-11-8 0:42:57 >
# 4 Re: javascript oop
if you bother to check my code, you'll see that im already using onmousedown.
I'm trying to get it to work with creating tags at runtime (you'll see that too if you check the code).
verifier at 2007-11-8 0:43:59 >
# 5 Re: javascript oop
Yes, I can see that. But creating them at runtime would not be your best option. It will decrease page performance and you have less versatility if you do not code the tag individually.
PeejAvery at 2007-11-8 0:45:00 >
# 6 Re: javascript oop
Im doing a lot of client side processing of the data (like hiding entries, sorting the data). To be able to do all this, all the data is stored in a javascript two dimensional array. And the html table is created with the help of this array.

That's why I need to hook the events / create the table by code and not by html.

It would be much slower to send the data back and forth between the browser/server to allow, for instance, php to do the processing instead.

I would love to hear a better way to do this, or better yet: to get a solution to my original question.
verifier at 2007-11-8 0:46:08 >
# 7 Re: javascript oop
Well, then can you post more code? The code you provided doesn't tell much about how the tables are created at runtime using a two dimensional array.
PeejAvery at 2007-11-8 0:47:04 >
# 8 Re: javascript oop
Yes it do. The display function have two for loops that go through the array. It creates the rows and the table cells.

for (var i = 1; i < this.mRows.length; ++i)
{
var row = table.insertRow(i);
[...]

var cell = null;
for (var j = 0; j < this.mRows[i].length; ++j)
{
cell = row.insertCell(j);
cell.textContent = this.mRows[i][j];
[...]
}
}
verifier at 2007-11-8 0:48:09 >
# 9 Re: javascript oop
Why do you rely on this so much? Can you post the whole page? Code in parts cannot be decoded because there are references to other parts within the parts you have posted.
PeejAvery at 2007-11-8 0:49:12 >
# 10 Re: javascript oop
All the code shoulnd be needed.
Why I rely on 'this'? Because im coding objectoriented javascript.

If you dont know what that means:
http://mckoss.com/jscript/object.htm
verifier at 2007-11-8 0:50:13 >
# 11 Re: javascript oop
If you dont know what that means:
http://mckoss.com/jscript/object.htm
I know exactly what it is.

Back to your original question...
Why do the alert report "object HTMLTableRowElement" instead of "object object". Shouldnt "this" contain a reference to the Table class?
This will not refer to a class but the object to which it is attached. What exactly is Table.prototype.modifiers?
PeejAvery at 2007-11-8 0:51:08 >
# 12 Re: javascript oop
it's a method that is included in the first post.
verifier at 2007-11-8 0:52:09 >
# 13 Re: javascript oop
it's a method that is included in the first post.
I know that. That is where I got it from.

What I am asking is how does that fire? I don't see that code.
PeejAvery at 2007-11-8 0:53:08 >
# 14 Re: javascript oop
From the first post:

row.onmousedown = this.modifiers;
verifier at 2007-11-8 0:54:17 >
# 15 Re: javascript oop
From the first post:

row.onmousedown = this.modifiers;

Yes, I see that. But what before that, and before that...

As I have stated, we need to see the whole code in order to back track.
PeejAvery at 2007-11-8 0:55:15 >
# 16 Re: javascript oop
Sorry, i do not understand what you mean with "before that".
There are no more code involved in capturing the mousedown event. I do not want to post the complete source.

If you have any hint to why it doesnt work, please say so.
If you never have hooked events by just code, or coded javascript oop, stop asking questions.
verifier at 2007-11-8 0:56:16 >
# 17 Re: javascript oop
Since you do not seem to like my posts, I will leave this thread alone. Below is an explanation of my reasoning.

If you have any hint to why it doesnt work, please say so.
I don't understand why you did the method the way you did. That is why I am asking questions. Now, without the full source, I won't be able to understand why you have it coded as you do because I can't see the whole picture.

If you never have hooked events by just code, or coded javascript oop, stop asking questions.
I have been coding JavaScript professionally for 9 years, I have done hooks thousands of times. If I did not understand, I would not be asking questions.
PeejAvery at 2007-11-8 0:57:16 >