Skip to content

Instantly share code, notes, and snippets.

@ayrton
Created August 22, 2012 11:35
Show Gist options
  • Save ayrton/3424708 to your computer and use it in GitHub Desktop.
Save ayrton/3424708 to your computer and use it in GitHub Desktop.
Coffeescript (after) vs. JavaScript (before)
class Card
constructor: (selector) ->
@$container = $('.cards')
@$element = @$container.find(selector)
@$text = @$element.find('.card-menu li:first-child a span')
toggleClass: ->
@$element.toggleClass('is-favorited')
changeText: ->
cardText = if @$element.favorited then 'Unfavorite' else 'Favorite'
@$text.text(cardText)
sort: ->
@$container.trigger('isotope:sort')
favorited: ->
@$element.hasClass('is-favorited')
$ ->
card = new Card('#card-<%= @id %>')
card.toggleClass()
card.changeText()
card.sort()
$container = $('.cards');
$card = $container.find('#card-<%= @id %>');
$cardText = $card.find('.card-menu li:first-child a span');
$card.toggleClass('is-favorited');
if ($card.hasClass('is-favorited')) {
cardText = 'Unfavorite';
} else {
cardText = 'Favorite';
}
$cardText.text(cardText);
$container.trigger('isotope:sort');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment