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

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

Expand Messages
  • Jean-Charles Meyrignac
    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]
    • Show all 5 messages in this topic