Javascript 1.3

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Benson-Manica

    Javascript 1.3

    Can anyone tell me which browsers implement Javascript 1.3?
    Specifically, which browsers will handle the identity operator (===)
    correctly? I ask because jslint suggests using it, but I don't want
    to get too cutting edge.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
  • Martin Honnen

    #2
    Re: Javascript 1.3



    Christopher Benson-Manica wrote:[color=blue]
    > Can anyone tell me which browsers implement Javascript 1.3?
    > Specifically, which browsers will handle the identity operator (===)
    > correctly? I ask because jslint suggests using it, but I don't want
    > to get too cutting edge.[/color]

    Netscape browsers support Javascript 1.3 and === since 4.06 and later
    version, IE (at least on Windows) should have support for === since IE4
    but that is only from my recollection, the JScript docs don't tell that
    in detail.
    --

    Martin Honnen


    Comment

    • Christopher Benson-Manica

      #3
      Re: Javascript 1.3

      Martin Honnen <mahotrash@yaho o.de> spoke thus:
      [color=blue]
      > Netscape browsers support Javascript 1.3 and === since 4.06 and later
      > version, IE (at least on Windows) should have support for === since IE4
      > but that is only from my recollection, the JScript docs don't tell that
      > in detail.[/color]

      I see. Another question: If I explicitly specify JS1.3 like so:

      <script type=\"text/javascript1.3\" >

      (well, I suppose that's how it's done...), and the browser does not
      implement 1.3, what will the browser do?

      --
      Christopher Benson-Manica | I *should* know what I'm talking about - if I
      ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

      Comment

      • Martin Honnen

        #4
        Re: Javascript 1.3



        Christopher Benson-Manica wrote:

        [color=blue]
        > Another question: If I explicitly specify JS1.3 like so:
        >
        > <script type=\"text/javascript1.3\" >
        >
        > (well, I suppose that's how it's done...), and the browser does not
        > implement 1.3, what will the browser do?[/color]

        If you want to use a version then you would need the language attribute e.g.
        <script language="JavaS cript1.3">
        older browsers like Netscape 4.00-4.05 or Netscape 3 then ignore the
        script element's content.

        But nowadays you shouldn't need to use <script language>, simply use
        <script type="text/javascript">
        the need for versioning your script elements is gone, if someone is
        still around with Netscape 4 then hardly with 4.00-4.05 and with IE5 and
        later there shouldn't be any problems either

        --

        Martin Honnen


        Comment

        • Richard Cornford

          #5
          Re: Javascript 1.3

          Martin Honnen wrote:
          <snip>[color=blue]
          > ... , IE (at least on Windows) should have support for === since
          > IE4 but that is only from my recollection, the JScript docs don't
          > tell that in detail.[/color]

          I believe that it was IE 5.0 that was the first IE browser to be
          released with a JScript version that supported - === -, but JScript on
          windows is independent of the browsers so even an IE 4 user may have a
          later JScript version installed (if they have updated WSH, for example)
          and IE 4 would use that version to execute scripts.

          Richard.


          Comment

          • Matt Kruse

            #6
            Re: Javascript 1.3

            "Martin Honnen" <mahotrash@yaho o.de> wrote:[color=blue]
            > If you want to use a version then you would need the language attribute[/color]
            e.g.[color=blue]
            > <script language="JavaS cript1.3">
            > older browsers like Netscape 4.00-4.05 or Netscape 3 then ignore the
            > script element's content.
            > But nowadays you shouldn't need to use <script language>, simply use
            > <script type="text/javascript">[/color]

            This is often said, but this is a good example - if a person wants to use
            ===, and doesn't specify the language="Javas script1.2" then how can they
            make sure older browsers don't execute the code block?

            The typical answer is "test for features" but you can't test for new
            operators like you can for properties of objects. If you use try/catch, then
            that breaks in older browsers.

            How can a developer use === and not break older browsers?

            --
            Matt Kruse
            Javascript Toolbox: http://www.mattkruse.com/javascript/


            Comment

            • Martin Honnen

              #7
              Re: Javascript 1.3



              Matt Kruse wrote:
              [color=blue]
              > "Martin Honnen" <mahotrash@yaho o.de> wrote:
              >[color=green]
              >>If you want to use a version then you would need the language attribute[/color]
              >
              > e.g.
              >[color=green]
              >> <script language="JavaS cript1.3">
              >>older browsers like Netscape 4.00-4.05 or Netscape 3 then ignore the
              >>script element's content.
              >>But nowadays you shouldn't need to use <script language>, simply use
              >> <script type="text/javascript">[/color]
              >
              >
              > This is often said, but this is a good example - if a person wants to use
              > ===, and doesn't specify the language="Javas script1.2" then how can they
              > make sure older browsers don't execute the code block?[/color]

              1.2 doesn't help as === is 1.3 but maybe that is a typo.

              [color=blue]
              > The typical answer is "test for features" but you can't test for new
              > operators like you can for properties of objects. If you use try/catch, then
              > that breaks in older browsers.
              >
              > How can a developer use === and not break older browsers?[/color]

              One way I see is using several script blocks and probably external
              script files with different versions (e.g. one using === and one using
              ==) in the following way:

              <script type="text/javascript">
              var idTest = false;
              </script>
              <script type="text/javascript">
              idTest = 1 === 1;
              </script>
              <script type="text/javascript">
              if (idTest) {
              var src = 'fileId.js';
              }
              else {
              var src = 'file.js';
              }
              document.write( '<script type="text/javascript" src="' + src +
              '"><\/script>');
              </script>

              With older browsers the second script block should yield a syntax error
              and therefore in the third script block the variable idTest is false so
              you can write out a reference to a file.

              A similar scheme should work for try/catch e.g.

              <html>
              <head>
              <title>Checki ng for try/catch</title>
              <script type="text/javascript">
              var tcTest = false;
              </script>
              <script type="text/javascript">
              try {
              tcTest = true;
              }
              catch (e) {

              }
              </script>
              <script type="text/javascript">
              if (tcTest) {
              var src = 'test20040416tc .js';
              }
              else {
              var src = 'test20040416.j s';
              }
              document.write( '<script type="text/javascript" src="' + src +
              '"><\/script>');
              </script>
              </head>
              <body>
              </body>
              </html>

              with test20040416tc. js being for test cases just

              alert('Could use try/catch here.');

              and the other file then

              alert('Can\'t use try/catch here.');



              That way if you try the test case with Netscape 4 which doesn't support
              try/catch no error is generated and you can load a script file which
              doesn't use try/catch.


              But as said I think you can safely ignore browsers not supporting ===,
              you can't forever try to make sure your script doesn't break with
              antiquated browsers.
              As for try/catch if you still think you have to deal with Netscape 4
              users then you have the choice to avoid try/catch totally or use an
              approach as outlined above. There are also other ways to use try/catch
              in certain browsers safely (e.g. IE with conditional comments, Netscape
              6/7 respectively Mozilla with <script type="text/javascript;
              version=1.5">) if you are only scripting features for those browser like
              XMLHttpRequest.
              --

              Martin Honnen


              Comment

              • Michael Winter

                #8
                Re: Javascript 1.3

                On Fri, 16 Apr 2004 11:15:18 -0500, Matt Kruse <newsgroups@mat tkruse.com>
                wrote:

                [snip]
                [color=blue]
                > How can a developer use === and not break older browsers?[/color]

                You probably can't, but you can avoid it altogether.

                function isExact( a, b ) {
                return(( typeof a == typeof b ) && ( a == b ));
                }

                This is results in exactly the same algorithm, just less efficient (the
                typeof comparison is a string comparison, rather than a direct type check).

                Mike

                --
                Michael Winter
                M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

                Comment

                • Matt Kruse

                  #9
                  Re: Javascript 1.3

                  "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote:[color=blue][color=green]
                  > > How can a developer use === and not break older browsers?[/color]
                  > You probably can't, but you can avoid it altogether.[/color]

                  Which is why I think it's ridiculous that type="text/javascript" is supposed
                  to replace language="Javas cript".

                  Same think with try/catch, or any other keyword additions and language
                  changes in different versions.
                  If you're developing for an internet audience, you can't use any of these
                  new features, because there is no way (that I've found) to degrade nicely,
                  without relying on language="Javas cript1.3", etc.

                  Causing a syntax error while determining whether or not an operator is
                  supported (as another poster suggested) isn't really a good solution, IMO.

                  --
                  Matt Kruse
                  Javascript Toolbox: http://www.mattkruse.com/javascript/




                  Comment

                  • Lasse Reichstein Nielsen

                    #10
                    Re: Javascript 1.3

                    "Matt Kruse" <newsgroups@mat tkruse.com> writes:
                    [color=blue]
                    > Same think with try/catch, or any other keyword additions and language
                    > changes in different versions.
                    > If you're developing for an internet audience, you can't use any of these
                    > new features, because there is no way (that I've found) to degrade nicely,
                    > without relying on language="Javas cript1.3", etc.[/color]

                    The problem with the language attribute is that not all browser honor it,
                    and that later versions are not necessarily compatible with earlier code.
                    Example of the latter:
                    <script language="Javas cript1.2">
                    var a=1,b=2;
                    if (a=b) {alert("Foo!"); }
                    </script>

                    This should not alert "Foo!", but in browsers that support Javascript
                    1.3 and *not* 1.2, it will (one example is IE 6).
                    That is, supporting Javascript1.3 does not mean that one supports 1.2!

                    /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

                    • Dr John Stockton

                      #11
                      Re: Javascript 1.3

                      JRS: In article <c5oqn1$bjk$1$8 302bc10@news.de mon.co.uk>, seen in
                      news:comp.lang. javascript, Richard Cornford
                      <Richard@litote s.demon.co.uk> posted at Fri, 16 Apr 2004 15:30:57 :[color=blue]
                      >Martin Honnen wrote:
                      ><snip>[color=green]
                      >> ... , IE (at least on Windows) should have support for === since
                      >> IE4 but that is only from my recollection, the JScript docs don't
                      >> tell that in detail.[/color]
                      >
                      >I believe that it was IE 5.0 that was the first IE browser to be
                      >released with a JScript version that supported - === -, but JScript on
                      >windows is independent of the browsers so even an IE 4 user may have a
                      >later JScript version installed (if they have updated WSH, for example)
                      >and IE 4 would use that version to execute scripts.[/color]

                      The initial UK release of Win98 came with an MSIE4 that accepts all but
                      the now commented-out line of
                      var A, B
                      A=B
                      A==B
                      A===B
                      // A====B

                      --
                      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
                      <URL:http://www.merlyn.demo n.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
                      <URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.

                      Comment

                      • Matt Kruse

                        #12
                        Re: Javascript 1.3

                        "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote:[color=blue]
                        > <script language="Javas cript1.2">
                        > var a=1,b=2;
                        > if (a=b) {alert("Foo!"); }
                        > </script>
                        > This should not alert "Foo!", but in browsers that support Javascript
                        > 1.3 and *not* 1.2, it will (one example is IE 6).[/color]

                        I'm not sure what you mean, here. It _should_ alert Foo, from what I
                        understand. a=b evaluates to 2 as an expression, which is true, which makes
                        the alert fire. If b is 0, then it does not fire. The exception is in
                        Netscape browsers, which treated this situation differently when explicitly
                        specifying "Javascript 1.2" as the language.
                        [color=blue]
                        > That is, supporting Javascript1.3 does not mean that one supports 1.2![/color]

                        It certainly should. I think the example you're pointing out is an exception
                        in Netscape browsers.
                        Someone feel free to correct me :)

                        --
                        Matt Kruse
                        Javascript Toolbox: http://www.mattkruse.com/javascript/


                        Comment

                        • Lasse Reichstein Nielsen

                          #13
                          Re: Javascript 1.3

                          "Matt Kruse" <newsgroups@mat tkruse.com> writes:
                          [color=blue]
                          > I'm not sure what you mean, here. It _should_ alert Foo, from what I
                          > understand. a=b evaluates to 2 as an expression, which is true, which makes
                          > the alert fire. If b is 0, then it does not fire. The exception is in
                          > Netscape browsers, which treated this situation differently when explicitly
                          > specifying "Javascript 1.2" as the language.[/color]

                          Yes, because they actually implement Javascript1.2. In JS1.2, "=" in
                          if-statments was treated as a comparison. In JS1.3 (and 1.1) it wasn't.

                          If you request JS1.3, you don't want browsers that doesn't support it
                          (but only, e.g., 1.2) to run the script. Running an 1.3 script with
                          an 1.2 interpreter will give wrong results.

                          My point is that running an 1.2 script with an 1.3 interpreter will
                          *also* give the wrong result. However, no browser supporting only 1.3
                          scripts will skip script with language="Javas cript1.2".
                          [color=blue][color=green]
                          >> That is, supporting Javascript1.3 does not mean that one supports 1.2![/color]
                          >
                          > It certainly should.[/color]

                          Only if 1.3 is a pure extension of 1.2. It isn't.
                          [color=blue]
                          > I think the example you're pointing out is an exception
                          > in Netscape browsers.[/color]

                          That exception would be recognizing and respecting the language
                          attribute.

                          /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

                          • Richard Cornford

                            #14
                            Re: Javascript 1.3

                            Dr John Stockton wrote:
                            <snip>[color=blue][color=green]
                            >> ... (if they have updated WSH, for example) and
                            >> IE 4 would use that version to execute scripts.[/color]
                            >
                            > The initial UK release of Win98 came with an MSIE4 that accepts all
                            > but the now commented-out line of
                            > var A, B
                            > A=B
                            > A==B
                            > A===B
                            > // A====B[/color]

                            Out of curiosity, what sort of output do you get from the following:-

                            var out = 'No ScriptEngine Funciton';
                            if(window.Scrip tEngine){
                            out = ScriptEngine();
                            if(window.Scrip tEngineMajorVer sion){
                            out += ' '+ScriptEngineM ajorVersion();
                            }
                            if(window.Scrip tEngineMinorVer sion){
                            out += '.'+ScriptEngin eMinorVersion() ;
                            }
                            if(window.Scrip tEngineBuildVer sion){
                            out += '.'+ScriptEngin eBuildVersion() ;
                            }
                            }
                            alert(out);

                            Richard.


                            Comment

                            • Lasse Reichstein Nielsen

                              #15
                              Re: Javascript 1.3

                              "Richard Cornford" <Richard@litote s.demon.co.uk> writes:
                              [color=blue][color=green]
                              >> The initial UK release of Win98 came with an MSIE4 that accepts all
                              >> but the now commented-out line of
                              >> var A, B
                              >> A=B
                              >> A==B
                              >> A===B[/color][/color]
                              [color=blue]
                              > Out of curiosity, what sort of output do you get from the following:-[/color]

                              I just tested a stand-alone version of IE 4 that accepts ===, and it
                              reports: JScript 3.1.3510

                              /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

                              Working...