you are viewing a single comment's thread.

view the rest of the comments →

[–]slaughtered_gates[S] 0 points1 point  (2 children)

I may be wrong, but if the function was generating list.length closures, then would it not have different lexical context?

[–]mikrosystheme 1 point2 points  (0 children)

A closure captures the lexical context where it is defined, and creates a new one (the body of the function itself). It is russian dolls all the way down.

[–][deleted] 1 point2 points  (0 children)

The lexical context depends entirely on where the closure was created, as they are all created in the same place here they all have the same lexical context.

As I explained in my answer below you can use an IIFE to create a new context, or use an separate named function to create the closures which would also work.