By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,969 Members | 1,735 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,969 IT Pros & Developers. It's quick & easy.

How do I make this work for W3C?

P: n/a
What do I put for the W3C part of this code?

function dot(i)
{
this.X = Xpos;
this.Y = Ypos;
this.dx = 0;
this.dy = 0;
if (isNetscape4) {
this.obj = eval("document.dot" + i);
} else if (isIE) {
this.obj = eval("dot" + i + ".style");
} else if (isW3C) {
this.obj = ?????????????
}
}

var dots = new Array(nDots);
var i = 0;
for (i = 0; i < nDots; i++) {
dots[i] = new dot(i);
}
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"David W. Deley" <de****@gte.net> writes:
What do I put for the W3C part of this code?
Code is *not* obvious, especially without comments. That means
we have to guess what you want the code to do.
function dot(i)
{
this.X = Xpos;
this.Y = Ypos;
this.dx = 0;
this.dy = 0;
if (isNetscape4) {
Any browser detection almost almways have failures. Trying to detect
Netscape 4 is not as efficient as detecting the absence of better
approaches and testing for the success of this one.
this.obj = eval("document.dot" + i);
Never use eval to access properties. Never! (With overwhelming
probability, you'll never need to use eval at all, since there are
safer and more efficient alternatives to all the common (mis)uses of
eval).
} else if (isIE) {
this.obj = eval("dot" + i + ".style");
} else if (isW3C) {
this.obj = ?????????????
I assume that you are trying to find an element with, e.g., id="dot2".

I recommned this approach:
---
var id = "dot"+i;
if (document.getElementById) {
this.obj = document.getElementById(id);
} else if (document.all) {
this.obj = document.all[id];
} else if (document[id]) {
this.obj = document[id];
}
---
No browser detection. Testing for known access methods first and
falling back on less standardized methods. If a browser has both
document.getElementById and document.layers, it will use the standard
method (yes, such browsers exist, and would be likely to be
misidentified as Neetscape 4).
dots[i] = new dot(i);


Traditionally, functions used as constructors are capitalized, so
I would change "dot" to "Dot".

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2

P: n/a
Fabulous. That should work great. Thank you. (I'm modifying code
someone else wrote.) -D.D.

Lasse Reichstein Nielsen wrote:

"David W. Deley" <de****@gte.net> writes:
What do I put for the W3C part of this code?


Code is *not* obvious, especially without comments. That means
we have to guess what you want the code to do.
function dot(i)
{
this.X = Xpos;
this.Y = Ypos;
this.dx = 0;
this.dy = 0;
if (isNetscape4) {


Any browser detection almost almways have failures. Trying to detect
Netscape 4 is not as efficient as detecting the absence of better
approaches and testing for the success of this one.
this.obj = eval("document.dot" + i);


Never use eval to access properties. Never! (With overwhelming
probability, you'll never need to use eval at all, since there are
safer and more efficient alternatives to all the common (mis)uses of
eval).
} else if (isIE) {
this.obj = eval("dot" + i + ".style");
} else if (isW3C) {
this.obj = ?????????????


I assume that you are trying to find an element with, e.g., id="dot2".

I recommned this approach:
---
var id = "dot"+i;
if (document.getElementById) {
this.obj = document.getElementById(id);
} else if (document.all) {
this.obj = document.all[id];
} else if (document[id]) {
this.obj = document[id];
}
---
No browser detection. Testing for known access methods first and
falling back on less standardized methods. If a browser has both
document.getElementById and document.layers, it will use the standard
method (yes, such browsers exist, and would be likely to be
misidentified as Neetscape 4).
dots[i] = new dot(i);


Traditionally, functions used as constructors are capitalized, so
I would change "dot" to "Dot".

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.