making the each fixture a little more like underscore, and avoiding passing assignment into functions from the outside

This commit is contained in:
Jeremy Ashkenas
2009-12-19 00:45:36 -05:00
parent 0b2e7f1e59
commit 9ba1ffde21
4 changed files with 18 additions and 16 deletions

View File

@@ -3,9 +3,12 @@
_.each: obj, iterator, context =>
index: 0
try
return obj.forEach(iterator, context) if obj.forEach
return iterator.call(context, item, i, obj) for item, i in obj. if _.isArray(obj) or _.isArguments(obj)
iterator.call(context, obj[key], key, obj) for key in _.keys(obj).
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 aint breaker.
obj.