• ## Closure with outer parameters question

(3)
• NextPrevious
• 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
View Source
• 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?
• ... Thanks. Please try it now.
Message 2 of 3 , Mar 12 3:56 PM
View Source
• 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?

• ... That was fast -- thanks! It now reports t, x, y as closure variables.
Message 3 of 3 , Mar 12 5:05 PM
View Source
• 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.