Skip to content

Instantly share code, notes, and snippets.

@julesbou
Created March 11, 2016 17:34
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 julesbou/ca96f4efa06178e09d13 to your computer and use it in GitHub Desktop.
Save julesbou/ca96f4efa06178e09d13 to your computer and use it in GitHub Desktop.
// save a reference to route() method
var $route = Backbone.Router.prototype.route;
// then override it
Backbone.Router.prototype.before = function() {}
Backbone.Router.prototype.after = function() {}
Backbone.Router.prototype.route = function(route, name, callback) {
if (_.isFunction(name)) {
callback = name;
name = '';
}
if (!callback) {
callback = this[name];
}
// wrap our initial callback with before() and after()
var wrapped = _.bind(function() {
this.before.apply(this, arguments);
callback.apply(this, arguments);
this.after.apply(this, arguments);
}, this);
return $route.call(this, route, name, wrapped);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment