Click to See Complete Forum and Search --> : javascript oop
verifier
September 14th, 2006, 10:11 AM
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';
}
}
PeejAvery
September 14th, 2006, 10:49 AM
If this is not included in the object events, it will automatically default to the window, not to the element being referenced.
verifier
September 14th, 2006, 10:53 AM
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.
PeejAvery
September 14th, 2006, 10:56 AM
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)
verifier
September 14th, 2006, 12:18 PM
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).
PeejAvery
September 14th, 2006, 12:24 PM
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.
verifier
September 14th, 2006, 04:05 PM
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.
PeejAvery
September 14th, 2006, 04:43 PM
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.
verifier
September 15th, 2006, 01:56 AM
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];
[...]
}
}
PeejAvery
September 15th, 2006, 09:04 AM
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.
verifier
September 15th, 2006, 09:37 AM
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
PeejAvery
September 15th, 2006, 09:41 AM
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?
verifier
September 15th, 2006, 09:46 AM
it's a method that is included in the first post.
PeejAvery
September 15th, 2006, 09:51 AM
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.
verifier
September 15th, 2006, 09:54 AM
From the first post:
row.onmousedown = this.modifiers;
PeejAvery
September 15th, 2006, 12:16 PM
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.
verifier
September 16th, 2006, 10:23 AM
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.
PeejAvery
September 16th, 2006, 03:38 PM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.