4 ms·
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,
by csense 14y ago
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 https://github.com/jashkenas/coffee-script/issues/467
[2] https://gist.github.com/2271874 https://gist.github.com/2271874