...

View Full Version : Object.prototype help



beetle
08-23-2002, 05:07 PM
Hey everyone

I'm scrambling to become more familiar with OO concepts, and specifically applying them to my javascript. So, as part of my self-education, I'm messing with prototype. I've done, this, but get a "not supported method" error.
<html>
<title>Prototype testing</title>
<head>
<script type="text/javascript">
TR.prototype.toggle = function() {
this.style.backgroundColor = 'red';
}
</script>

</head>

<body>
<table cellspacing="1">
<tr onMouseOver="this.toggle()"><td>1</td><td>2</td><td>3</td></tr>
<tr onMouseOver="this.toggle()"><td>1</td><td>2</td><td>3</td></tr>
<tr onMouseOver="this.toggle()"><td>1</td><td>2</td><td>3</td></tr>
</table>
</body>
</html>

jkd
08-23-2002, 05:27 PM
IE's HTMLElement's are all screwed up - you'll find they don't even inherit from Object!

So far, only Mozilla exposes prototypes of HTMLElement's:

HTMLTableRowElement.prototype.toggle = function() {
this.style.backgroundColor = 'red';
}

See http://www.w3.org/TR/2002/CR-DOM-Level-2-HTML-20020605/html.html for a list of interfaces you can use.

beetle
08-23-2002, 05:46 PM
I see, so can I not do this in IE period?

http://www.ie.com/images/logos/internetexplorer.gif http://www.simonsgroup.com/siteimages/s/bigun2.gif

jkd
08-23-2002, 05:55 PM
Not in this fashion. You could resort to a behavior (just like you could resort to Moz's XBL):

tr {
behavior: url(bla.htc);
}

and inside bla.htc have:

<script type="text/javascript">
element.toggle = function() {
element.style.backgroundColor = 'red';
}
</script>


But that's not really extending your OO knowledge, now is it? ;)

beetle
08-23-2002, 06:00 PM
No, it's not :(

Thanks, I know behaviors and XBL (a little)

Got a good reference link for XBL?

NS6 sees -moz-binding :url(blah); right?

jkd
08-23-2002, 06:07 PM
Originally posted by beetle
NS6 sees -moz-binding :url(blah); right?

Yes. See XBL 1.0 (http://www.mozilla.org/projects/xbl/xbl.html) specification, but beware, the current XBL implementation in Mozilla is not yet the 1.0 phase, which means a lot of the features in that document currently don't exist, or been disabled to stability, etc.
This (http://www.mozdev.org/source/browse/xblref/docs/) is documentation of the current implementation. But it is on a webbased CVS interface, which means non-CVS people might get slightly confused, but you can always start here (http://www.mozdev.org/source/browse/~checkout~/xblref/docs/bindings.html?rev=1.3&content-type=text/html) and follow links without worrying about CVS extras.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum