Progranomicon

~= A Ruby, JavaScript, and Erlang Blog =~

May 16th 2013

Backbone: dynamically change view events upon initialization

Just for people who might find this, you can modify the events object in your initialize method like so:

var MyView = Backbone.View.extend({

  events: {
    'click .foo': 'handleClickFoo'
  },

  initialize: function(options) {

    // Add an event
    if ( /* something */ ) {
      this.events['click .save'] = function() {
March 12th 2012

The Use of Self on Yourself

I was having trouble finding answers about how to implement my own bang methods in Ruby, so I figured some things out and consolidated what little info there is here. Bang! methods are methods that end with an exclamation point--this is only a convention, not a language construct--and simply mean "Hey! Pay attention to what you're doing here!", but more often than not, they modifiy the calling object's value... so for instance, like this:

Recent posts