mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 19:11:22 -05:00
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:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user