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

Re: Unused Variables

Expand Messages
  • Douglas Crockford
    ... Unused variables are usually an indication of a mistake and should be reported. new should only be used to create objects, so new Stupid; should produce a
    Message 1 of 5 , Apr 4, 2011
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "James" <jacob@...> wrote:
      > I like the unused variables warning, because it helps catch misspelled
      > variables, although so do checks that warn about undeclared variables.
      >
      > However, using YUI I regularly have undefined variables, where I
      > instantiate a library with "new", which must be set to a variable, and
      > then I don't use the variable. Even YUI3 does this often. Is this just
      > a bad idea by me and YUI3? Or should JSLint not complain about some
      > instances of unused variables?

      Unused variables are usually an indication of a mistake and should be reported.

      new should only be used to create objects, so

      new Stupid;

      should produce a warning.

      It is ok to use new and then use its result immediately.

      new Thing().exec();
    • Morgaut Alexandre Louis Marc
      ... So new XMLHttpRequest( POST , /log ).send(logText); should be ok ;-) The message returned by JSLint otherwise is: Do not use ‘new’ for side
      Message 2 of 5 , Apr 4, 2011
      • 0 Attachment
        On 4 avr. 2011, at 19:14, Douglas Crockford wrote:
        > new should only be used to create objects, so
        >
        > new Stupid;
        >
        > should produce a warning.
        >
        > It is ok to use new and then use its result immediately.
        >
        > new Thing().exec();
        >

        So

        new XMLHttpRequest('POST', '/log').send(logText);

        should be ok ;-)

        The message returned by JSLint otherwise is: "Do not use �new� for side effects."

        Does that mean that widget constructors should in theory only create a reference to a widget, which would be then:
        - added to the DOM
        - or applied on a DOM Element
        through one of its methods ?

        [Non-text portions of this message have been removed]
      • Douglas Crockford
        ... It works for me. What are you using?
        Message 3 of 5 , Apr 4, 2011
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, Morgaut Alexandre Louis Marc <morgaut@...> wrote:
          > So
          >
          > new XMLHttpRequest('POST', '/log').send(logText);
          >
          > should be ok ;-)

          It works for me. What are you using?
        • Morgaut Alexandre Louis Marc
          ... It works for me also Sorry if it looked like I meant it didn t work My purpose was more about a common case in libraries and frameworks where new
          Message 4 of 5 , Apr 4, 2011
          • 0 Attachment
            On 5 avr. 2011, at 07:59, Douglas Crockford wrote:
            > --- In jslint_com@yahoogroups.com, Morgaut Alexandre Louis Marc <morgaut@...> wrote:
            > > So
            > >
            > > new XMLHttpRequest('POST', '/log').send(logText);
            > >
            > > should be ok ;-)
            >
            > It works for me. What are you using?
            >


            It works for me also
            Sorry if it looked like I meant it didn't work

            My purpose was more about a common case in libraries and frameworks where

            new AwesomeWidget();

            directly create and render a widget

            If I don't misinterpret the design guideline, they should better, be usable this way:

            new AwesomeWidget().render();



            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.