How do I make this work for W3C?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David W. Deley

    How do I make this work for W3C?

    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);
    }
  • Lasse Reichstein Nielsen

    #2
    Re: How do I make this work for W3C?

    "David W. Deley" <deleyd@gte.net > writes:
    [color=blue]
    > What do I put for the W3C part of this code?[/color]

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

    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.
    [color=blue]
    > this.obj = eval("document. dot" + i);[/color]

    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).
    [color=blue]
    > } else if (isIE) {
    > this.obj = eval("dot" + i + ".style");
    > } else if (isW3C) {
    > this.obj = ?????????????[/color]

    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.getEl ementById) {
    this.obj = document.getEle mentById(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.getEle mentById and document.layers , it will use the standard
    method (yes, such browsers exist, and would be likely to be
    misidentified as Neetscape 4).
    [color=blue]
    > dots[i] = new dot(i);[/color]

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

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

    Comment

    • David W. Deley

      #3
      Re: How do I make this work for W3C?

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

      Lasse Reichstein Nielsen wrote:[color=blue]
      >
      > "David W. Deley" <deleyd@gte.net > writes:
      >[color=green]
      > > What do I put for the W3C part of this code?[/color]
      >
      > Code is *not* obvious, especially without comments. That means
      > we have to guess what you want the code to do.
      >[color=green]
      > > function dot(i)
      > > {
      > > this.X = Xpos;
      > > this.Y = Ypos;
      > > this.dx = 0;
      > > this.dy = 0;
      > > if (isNetscape4) {[/color]
      >
      > 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.
      >[color=green]
      > > this.obj = eval("document. dot" + i);[/color]
      >
      > 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).
      >[color=green]
      > > } else if (isIE) {
      > > this.obj = eval("dot" + i + ".style");
      > > } else if (isW3C) {
      > > this.obj = ?????????????[/color]
      >
      > 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.getEl ementById) {
      > this.obj = document.getEle mentById(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.getEle mentById and document.layers , it will use the standard
      > method (yes, such browsers exist, and would be likely to be
      > misidentified as Neetscape 4).
      >[color=green]
      > > dots[i] = new dot(i);[/color]
      >
      > Traditionally, functions used as constructors are capitalized, so
      > I would change "dot" to "Dot".
      >
      > /L
      > --
      > Lasse Reichstein Nielsen - lrn@hotpop.com
      > DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      > 'Faith without judgement merely degrades the spirit divine.'[/color]

      Comment

      Working...