Browse Groups

• ## 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
Mar 12 1 of 3
View Source
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.
Mar 12 1 of 3
View Source
--- 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.
Mar 12 1 of 3
View Source
--- 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.
• Changes have not been saved
Press OK to abandon changes or Cancel to continue editing
• Your browser is not supported
Kindly note that Groups does not support 7.0 or earlier versions of Internet Explorer. We recommend upgrading to the latest Internet Explorer, Google Chrome, or Firefox. If you are using IE 9 or later, make sure you turn off Compatibility View.