Ticket #423. When functions are generated within comprehensions ... the comprehensions should close over the element instead of sharing it.

This commit is contained in:
Jeremy Ashkenas
2010-06-13 21:21:30 -04:00
parent 6f91331626
commit b0a45e5b93
4 changed files with 89 additions and 67 deletions

View File

@@ -62,18 +62,26 @@ ok 2 in evens
# Ensure that the closure wrapper preserves local variables.
obj: {}
methods: ['one', 'two', 'three']
for method in methods
name: method
obj[name]: ->
"I'm " + name
for method in ['one', 'two', 'three']
obj[method]: ->
"I'm " + method
ok obj.one() is "I'm one"
ok obj.two() is "I'm two"
ok obj.three() is "I'm three"
# Even when referenced in the filter.
list: ['one', 'two', 'three']
methods: for num in list when num isnt 'two'
-> num
ok methods.length is 2
ok methods[0]() is 'one'
ok methods[1]() is 'three'
# Naked ranges are expanded into arrays.
array: [0..10]
ok(num % 2 is 0 for num in array by 2)