2 ms·
The middle code example can further be broken down[2] by using coco[1] instead of coffee-script. JavaScript: this.originalStyle = {}; ['top', 'left',
by AndyKelley 14y ago
The middle code example can further be broken down[2] by using coco[1] instead of coffee-script.
JavaScript:
this.originalStyle = {};
['top', 'left', 'width', 'height'].each(function (k) {
this.originalStyle[k] = this.element.style[k];
}.bind(this));
Coffee-script:
@originalStyle = {}
for k in ['top', 'left', 'width', 'height']
@originalStyle[k] = @element.style[k]
coco:
@originalStyle = @element.style{'top', 'left', 'width', 'height'}
coco also solves a rather nasty variable scoping issue[3]
[1]: https://github.com/satyr/coco/ https://github.com/satyr/coco/
[2]: http://satyr.github.com/cup/#c:@originalStyle%20=%20@element.style%7Btop,%20left,%20width,%20height%7D http://satyr.github.com/cup/#c:@originalStyle%20=%20@element...
[3]: https://github.com/jashkenas/coffee-script/issues/712 https://github.com/jashkenas/coffee-script/issues/712