Skip to content

Instantly share code, notes, and snippets.

@friggeri
Created January 6, 2012 14:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save friggeri/1570840 to your computer and use it in GitHub Desktop.
Save friggeri/1570840 to your computer and use it in GitHub Desktop.
More CoffeeScriptish
do ($ = jQuery) ->
$.fn.zebraTable = (options) ->
defaults =
evenColor: '#ccc'
oddColor : '#eee'
options = $.extend(defaults, options)
@each ->
$("tr:even", @).css('background-color', options.evenColor)
$("tr:odd", @).css('background-color', options.oddColor)
@pfinkbeiner
Copy link

do ($ = jQuery) ->
$.fn.zebraTable = (options) ->
defaults =
evenColor: '#ccc'
oddColor : '#eee'

options = $.extend defaults, options
@each ->
  $("tr:even", @).css 'background-color', options.evenColor
  $("tr:odd", @).css 'background-color', options.oddColor

You can also reduce some ( & )

@ssokolow
Copy link

ssokolow commented Mar 9, 2013

@pfinkbeiner It's possible he included the parens on purpose. I know I do in all my CoffeeScript. It means less chance of misunderstanding how a function call is going to be parsed... especially if you code Python rather than Ruby or Haskell.

Also, if you ever see this, edit your comment and indent all your code by 4 spaces. That's the simplest way to indicate a code block in markdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment