is there a way to return an object from a comprehension in coffeescript? something so that i could express this:
form_values = () -> ret = {} ret[f.name] = f.value for f in $('input, textarea, select') return ret
like this:
form_values = () -> f.name, f.value for f in $('input, textarea, select')
i'd like to construct a single object (not an array of objects). so if the markup looks something like this:
<form name=blah> <input type=text name=blah1 value=111 /> <textarea name=blah2>222</textarea> <select name=blah3> <option value=333a> <option value=333b> </select> </form>
the returned object would be something like this:
{ blah1: '111', blah2: '222', blah3: '' }
form_values = new -> @[f.name] = f.value for f in $ 'input, textarea, select' this
or
form_values = new class then constructor: -> @[f.name] = f.value for f in $ 'input, textarea, select'
Nope. Comprehensions only return arrays in CoffeeScript. Search the issue tracker for object comprehensions, and you'll find several proposals, but none were found suitable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With