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

Re: Yet Another Global Question...

Expand Messages
  • santini.alberto
    ... Sorry for the delay... Usually I use the namespace approach or pseudo-block (function () {...}); In some cases, for instance, I forget the namespace part
    Message 1 of 6 , Nov 18, 2008
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...>
      wrote:
      >
      > --- In jslint_com@yahoogroups.com, "santini.alberto"
      > <albertosantini@> wrote:
      > >
      > > I was wondering if it would be better to get a warning for global bar
      > > function.
      >
      >
      > Can you suggest a case in which this would be useful?
      >

      Sorry for the delay...

      Usually I use the namespace approach or pseudo-block (function () {...});

      In some cases, for instance, I forget the namespace part and I am not
      in a pseudo-block, so that function would be global. :(

      Again I use javascript, server-side with Ajax server Jaxer, and the
      use of a namespace for the callbacks is not reliable (at the moment
      and in my context), forcing a global approach.

      So I was wondering it would be nice a little warning to fix later the
      code.

      P.S.: I prefer to use "function foo() {}" instead "var foo = function
      () {}" because I have not to declare the variable at the start of the
      function (if you are using onevar option in JSLint).

      Alberto
    • Douglas Crockford
      ... the namespace approach or pseudo-block (function () {...}); ... I do not understand the benefit of this warning.
      Message 2 of 6 , Nov 19, 2008
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "santini.alberto" > Usually I use
        the namespace approach or pseudo-block (function () {...});
        >
        > In some cases, for instance, I forget the namespace part and I am not
        > in a pseudo-block, so that function would be global. :(
        >
        > Again I use javascript, server-side with Ajax server Jaxer, and the
        > use of a namespace for the callbacks is not reliable (at the moment
        > and in my context), forcing a global approach.
        >
        > So I was wondering it would be nice a little warning to fix later the
        > code.
        >
        > P.S.: I prefer to use "function foo() {}" instead "var foo = function
        > () {}" because I have not to declare the variable at the start of the
        > function (if you are using onevar option in JSLint).

        I do not understand the benefit of this warning.
      • santini.alberto
        ... For sure I have been missing something... :) I thought a global function was evil, but I see the misunderstanding. If I lint (JSLINT) the code function
        Message 3 of 6 , Nov 20, 2008
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...>
          wrote:
          >
          > I do not understand the benefit of this warning.
          >

          For sure I have been missing something... :)
          I thought a global function was evil, but I see the misunderstanding.

          If I lint (JSLINT) the code "function foo() {}", I have no error or
          warning.

          Then, if I get the report (JSLINT.report), I see foo function reported
          correctly as global.

          Maybe it would be usefull to add an option (noglobal) to get a warning
          in that case.

          Or, finally, getting always the report. :)

          Regards,
          Alberto
        Your message has been successfully submitted and would be delivered to recipients shortly.