Im wondering if there is a cleaner way to write this -
map = (obj) ->
$scope.data.push({name : obj.name, id : obj.id})
map obj for obj in objArr
Specifically, I'm wondering if I can anonymize the map function.
Im wondering if there is a cleaner way to write this -
Specifically, I'm wondering if I can anonymize the map function. |
||||
I'd certainly do something about that function too. It's called But you can just do everything in the loop without introducing a function:
or, in a more readable fashion:
That's really just your code but unwrapped to get rid of the function. You could also keep the function if you often need the Heck, you can even do that as a one-liner, though it's a little too obtuse to really recommend:
Alternatively, you may use CoffeeScript's shorthand syntax for object literals and object destructuring:
It'd be neat if you could combine those into a single expression (aka Many general purpose utility libraries have something like this, though. For instance, Underscore has
In which case you do stuff like:
|
||||
|
i
though. Is it possible to get rid of it via a different function? – David Grinberg Oct 3 '14 at 21:28