adding a new comprehension 'for all key, value of object', which compiles to the naked JS for..in, including enumerable properties inherited from prototypes.

This commit is contained in:
Jeremy Ashkenas
2010-07-15 21:18:35 -04:00
parent 2a932597e4
commit 72c4efbc39
12 changed files with 177 additions and 124 deletions

View File

@@ -114,3 +114,17 @@ expr: ->
result: item * item for item in arguments
ok expr(2, 4, 8).join(' ') is '4 16 64'
# Fast object comprehensions over all properties, including prototypal ones.
class Cat
constructor: -> @name: 'Whiskers'
breed: 'tabby'
hair: 'cream'
whiskers: new Cat
own: value for key, value of whiskers
all: value for all key, value of whiskers
ok own.join(' ') is 'Whiskers'
ok all.sort().join(' ') is 'Whiskers cream tabby'