Closed andrewrk closed 12 years ago
The index is intentionally variable-only as using property for it is an anti-pattern performance-wise.
is there a better way to factor this class?
emit: !(event_name, ...args) -> # loop with @i so we can adjust if the user deletes # during the callback handler(...args) for handler, @i of handlers_list
I'd avoid iterating a dynamically changing list:
emit: !(event_name, ...args) ->
for h of @event_handlers@@[event_name]concat!
h.apply null, args
I think that is the cleanest way to factor the code. I originally copied the array before looping over it, but then wanted to avoid an array copy since emit is used in a game loop, which should be fast.
Anyway I think you're right that coco should not make it easy to iterate using an assignable other than a variable for the index.
code:
expected:
actual:
alternately, is there a better way to factor this class?