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

Closure with outer parameters question

Expand Messages
  • quintic
    Given... function f(x, y) { use strict ; var t = x; return function (z) { console.log(x + y + t + z); }; } ... JSLint reports: f(x, y) closure t, x Should y
    Message 1 of 3 , Mar 12 3:29 PM
    • 0 Attachment
      Given...

      function f(x, y) {
      'use strict';
      var t = x;
      return function (z) {
      console.log(x + y + t + z);
      };
      }

      ... JSLint reports:

      f(x, y)
      closure
      t, x
      Should y also be reported as a closure variable?
    • douglascrockford
      ... Thanks. Please try it now.
      Message 2 of 3 , Mar 12 3:56 PM
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "quintic" <nick_hobson@...> wrote:

        > Given...
        >
        > function f(x, y) {
        > 'use strict';
        > var t = x;
        > return function (z) {
        > console.log(x + y + t + z);
        > };
        > }
        >
        > ... JSLint reports:
        >
        > f(x, y)
        > closure
        > t, x
        > Should y also be reported as a closure variable?

        Thanks. Please try it now.
      • quintic
        ... That was fast -- thanks! It now reports t, x, y as closure variables.
        Message 3 of 3 , Mar 12 5:05 PM
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "douglascrockford" <douglas@...> wrote:
          >
          > --- In jslint_com@yahoogroups.com, "quintic" <nick_hobson@> wrote:
          >
          > > Given...
          > >
          > > function f(x, y) {
          > > 'use strict';
          > > var t = x;
          > > return function (z) {
          > > console.log(x + y + t + z);
          > > };
          > > }
          > >
          > > ... JSLint reports:
          > >
          > > f(x, y)
          > > closure
          > > t, x
          > > Should y also be reported as a closure variable?
          >
          > Thanks. Please try it now.
          >

          That was fast -- thanks! It now reports t, x, y as closure variables.
        Your message has been successfully submitted and would be delivered to recipients shortly.