Loading ...
Sorry, an error occurred while loading the content.

Re: [jslint] Re: catch (e) ... 'e' is already defined !?!

Expand Messages
  • Jean-Charles Meyrignac
    ... What boyopeg wanted to say is that Javascript has only a limited scope. In your original message, catch(error) generates multiple definitions in the
    Message 1 of 5 , Aug 11, 2010
    • 0 Attachment
      >
      > On Wed, Aug 11, 2010 at 11:06 AM, Alexandre Morgaut <morgaut@...>wrote:
      >


      What boyopeg wanted to say is that Javascript has only a limited scope.
      In your original message, catch(error) generates multiple definitions in the
      routine's scope (at least in IE).

      For example:

      function func1(test)
      {
      var a = 1;
      if (test)
      {
      var a = 2;
      var b;
      }
      alert(a);
      }

      The second 'var a' is the same as the first one, 'func1(true)' will display
      '2' and you'll also have a 'b' variable declared at the end of the routine.

      This is why we have ugly code for handling events in JS, because IE doesn't
      send the parent event on onclick for example:
      function onclickedobject(evt)
      {
      if (!evt) var evt = window.event; // just for IE, isn't that ugly ?
      }

      I also saw terrible code, where people didn't use the var keyword:
      function func()
      {
      for(i = 0;i<10;++i) // yes, this variable is global !!!
      etc...
      }
      I found these bugs when dumping the global variables.

      On Wed, Aug 11, 2010 at 11:06 AM, Alexandre Morgaut <morgaut@...>wrote:

      >
      >
      > Well it shouldn't
      > On which browser did you test it ?
      >
      > On Firefox
      > - this generate a ReferenceError: "error is not defined"
      >
      > On Safari:
      > - this generate also a ReferenceError: Can't find variable: error
      >
      > which is good
      >
      >
      You are nit-picking.
      The example boyopeg has provided is probably not the best one, since the
      behaviour is different from a browser to another.

      But anyway, we are all trying to write cross-browser code, so we ultimately
      need to consider IE's limitations.

      JC


      [Non-text portions of this message have been removed]
    • Alexandre Morgaut
      Hi Jean-Charles, You are perfectly right when you say that there is no specific scope in conditional blocks I know so far 4 kind of scopes in JavaScript: - the
      Message 2 of 5 , Aug 11, 2010
      • 0 Attachment
        Hi Jean-Charles,

        You are perfectly right when you say that there is no specific scope in conditional blocks

        I know so far 4 kind of scopes in JavaScript:
        - the global scope
        - the function scope
        - the with scope
        - & the catch scope

        "with" creates a specific scope in which all properties of an object are directly accessible... It highly discouraged to use it...

        the "catch" block requires an "identifier" set as a parameter for a function, create an object in matching to this exception "identifier" and remove it at the and of the catch block

        Maybe Douglas would have explained it another way but the idea is there

        So my surprise was to see that some User-Agent didn't implement this ECMAScript specificity as expected when ECMAScript level 3 exists from so far away

        So please Microsoft.. update JScript... Do IE8 and IE9 behave that quirky way too ?
      Your message has been successfully submitted and would be delivered to recipients shortly.