Page 1 of 1

Custom Painting with the JS DOM?

Posted: Tue Feb 27, 2007 7:35 am
by Chris Corbyn
I want to create an object which extends HTMLTableElement. Does anyone know if it's possible?

I can do it another way, I just like the way it would interface.

I have MarkBook (an object which will be a sublass of HTMLTableElement), MarkBookModel and MarkBookColumnModel. MarkBook is the view which renders the model of course.

If I could have MarkBook as a subclass of HTMLTableElement I could do something like this:

Code: Select all

var markbook = new MarkBook(new MarkBookModel(data));
document.getElementById("something").appendChild(markbook);

// ... SNIP ...
//some user actions etc...
// ... SNIP ...

markbook.getModel().getColumn(i).setValueAt(key, newValue);
markbook.repaint();
Or something to that effect. Anyone have an hints? I tried this but it just seems to destroy my class.

Code: Select all

function MarkBook(model)
{
    //
}
MarkBook.prototype = document.createElement("table");

Posted: Tue Feb 27, 2007 8:49 am
by feyd
I haven't seen anything that would make extension of the DOM elements not possible. The prototype property is the place to use.

Posted: Tue Feb 27, 2007 8:57 am
by Chris Corbyn
Weird... I wonder if it's got anything to do with the framework I'm using? Actually... it's probably does because I declare classes like this:

Code: Select all

var MarkBook = new Class({
    initialize : function() { /* this is the constructor */ }
});
The framework provides it's own extend() method but it didn't work with that (gave me errors in the framework itself) so I tried using prototype which subsequently made all my properties and methods disappear.

I found this: http://www.codeproject.com/jscript/MiniRacer.asp

Hardly focused though.