Skip to content

Instantly share code, notes, and snippets.

@colwilson
Created June 26, 2011 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colwilson/1047623 to your computer and use it in GitHub Desktop.
Save colwilson/1047623 to your computer and use it in GitHub Desktop.
class window.MainController extends Backbone.Controller
class window.Counter extends Backbone.Model
defaults:
count: 00
class window.CounterView extends Backbone.View
initialize: ->
@counter = new Counter()
@render()
el: $('#counter')
events:
'click button#inc-count' : 'inc'
'click button#dec-count' : 'dec'
render: ->
$(@el).find("#count").html "The count is " \
+ @counter.get("count")
@
inc: ->
ct = @counter.get("count")
@counter.set(count: ct+1)
@render()
dec: ->
ct = @counter.get("count")
@counter.set(count: ct-1)
@render()
head.ready ->
new MainController()
new CounterView()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment