Search

1/02/2012

The Pragmatic Bookshelf | PragPub 2011-05 | A CoffeeScript Intervention

The Pragmatic Bookshelf | PragPub 2011-05 | A CoffeeScript Intervention

5. Repetition, Repetition
I’ll let the code speak for itself:


x = sprite.x;
y = sprite.y;
css = {
opacity: opacity,
fontFamily: fontFamily
};
function(request) {
body = request.body;
status = request.status;
// ...
}

The CoffeeScript Way
Each snippet above becomes a one-liner, thanks to pattern-matching:

{x, y} = sprite
css = {opacity, fontFamily}
({body, status}) -> ...

沒有留言: