Skip to content

Instantly share code, notes, and snippets.

@joshforbes
Created May 27, 2015 11:53
Show Gist options
  • Save joshforbes/fe10404b300b4b90eacd to your computer and use it in GitHub Desktop.
Save joshforbes/fe10404b300b4b90eacd to your computer and use it in GitHub Desktop.
var counter = {
count: 0,
init: function() {
this.$count = $('#count');
this.setCount(parseInt(this.$count.text(), 10));
this.bindEvents();
},
bindEvents: function() {
$('#add').on('click', $.proxy(this.add, this));
$('#subtract').on('click', $.proxy(this.subtract, this));
},
add: function() {
this.setCount(this.count + 1);
},
subtract: function() {
this.setCount(this.count - 1);
},
setCount: function(val) {
this.count = val;
this.render();
},
render: function() {
this.$count.text(this.count);
}
};
counter.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment