1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/fixtures/each.cs
2009-12-24 17:21:20 -08:00

14 lines
No EOL
457 B
C#

# The cornerstone, an each implementation.
# Handles objects implementing forEach, arrays, and raw objects.
_.each: obj, iterator, context =>
index: 0
try
if obj.forEach
obj.forEach(iterator, context)
else if _.isArray(obj) or _.isArguments(obj)
iterator.call(context, item, i, obj) for item, i in obj.
else
iterator.call(context, obj[key], key, obj) for key in _.keys(obj)..
catch e
throw e if e isnt breaker.
obj.