News for hackers. Stuff that matters.
Re:Dropbox dives into CoffeeScript by csense on Thursday September 13, 2012 @04:58PM (#4518569)
Parent's reduce() example is harder to read than the original, and about the same length. If CoffeeScript had dictionary comprehensions like Python 2.7 / 3.x, we could make the code shorter while preserving and easier to comprehend:

  @originalStyle = {k : @element.style[k] for k in ['top', 'left', 'width', 'height'}
Unfortunately this syntax was proposed and rejected [1]. But with a simple to_hash library function, you can achieve something similar [2]:

  to_hash = (pairs) ->
     hash = {}
     hash[key] = value for [key, value] in pairs
     hash

  @originalStyle = to_hash ([k, @element.style[k]]
     for k in ['top', 'left', 'width', 'height'])
[1] https://github.com/jashkenas/coffee-script/issues/467

[2] https://gist.github.com/2271874

There are no comments on this comment yet.