Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Created November 18, 2012 00:59
Show Gist options
  • Save JeffreyWay/4102251 to your computer and use it in GitHub Desktop.
Save JeffreyWay/4102251 to your computer and use it in GitHub Desktop.
// Which do you prefer more?
// trigger event and get out
var vent = _.extend({}, Backbone.Events);
App.Router = Backbone.Router.extend({
routes: {
'show/:id': 'show'
},
show: function(id) {
vent.trigger('thing:show', id);
}
});
// Or, perform logic
App.Router = Backbone.Router.extend({
routes: {
'show/:id': 'show'
},
show: function(id) {
var thing = new Thing({ name: 'Joe'});
var thingView = new ThingView({ model: thing });
$(document.body).append(thingView.render().el);
}
});
@dilab
Copy link

dilab commented Nov 18, 2012

prefer "trigger event", cause that way the event is reusable for other callbacks.

@redsquare
Copy link

Ditto dilab

@mihaipaun
Copy link

+1 for the first approach for basically the same reason.

@oknoorap
Copy link

perform logic was simple

@hemantajax
Copy link

of-course 1st one because of the reason given by dilab.

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