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

1389Re: [jslint] Re: Implied global or hoisted var

Expand Messages
  • Marcel Duran
    Jul 27, 2010
    • 0 Attachment
      You could use:

      var foo, bar;

      foo = function () {
      bar();
      };

      bar = function () {
      foo();
      };

      Marcel

      On Tue, Jul 27, 2010 at 5:52 PM, bertbelder <bertbelder@...> wrote:

      >
      >
      >
      >
      > Allright. But what if I have two functions that mutually call each other
      > (that was when I ran into this)? Then there is always one that is
      > 'encountered' before it is defined.
      >
      > Furthermore, IMHO if JSLint isn't happy with a certain coding style, that's
      > what it should complain about -- instead of producing wrong statements about
      > the code.
      >
      >
      > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, Mark
      > Volkmann <r.mark.volkmann@...> wrote:
      > >
      > > JSLint wants you to define functions before their first call is
      > encountered.
      > > While your code would work the way you haven't, it's considered better
      > style
      > > to change the order of your code.
      > >
      > > On Tue, Jul 27, 2010 at 4:52 PM, Bert Belder <bertbelder@...> wrote:
      > >
      > > >
      > > >
      > > > When linting this code:
      > > >
      > > > (function outer() {
      > > > var foo = function() {
      > > > bar();
      > > > };
      > > >
      > > > var bar = function() {
      > > > };
      > > >
      > > > foo();
      > > > })();
      > > >
      > > > JSLint gives me these warnings:
      > > >
      > > > Problem at line 3 character 5: 'bar' is not defined.
      > > > Implied global: bar 3
      > > > Unused variable: bar 1 outer
      > > >
      > > > I think all three warnings are wrong. Due to type hoisting the 'var
      > bar'
      > > > declaration applies to the entire scope of the 'outer' function, so
      > foo()
      > > > inherits 'bar' from 'outer'.
      > > >
      > > > Or am I missing something here?
      > > >
      > > > best regards,
      > > > Bert
      > > >
      > > >
      > > >
      > >
      > >
      > >
      > > --
      > > R. Mark Volkmann
      > > Object Computing, Inc.
      > >
      > >
      > > [Non-text portions of this message have been removed]
      > >
      >
      >
      >



      --
      Marcel Duran


      [Non-text portions of this message have been removed]
    • Show all 10 messages in this topic