Skip to content

Instantly share code, notes, and snippets.

@phamann
Created June 13, 2013 16:38
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 phamann/5775264 to your computer and use it in GitHub Desktop.
Save phamann/5775264 to your computer and use it in GitHub Desktop.
Require.js for ben
//You are using underscores extend so you need include it :)
define(['underscore'], function(_) {
//This could be some kind of utilities modules
//Define the extend method
var extend = function() {
_.extend(Backbone.Router.prototype, Backbone.Events, {
before: function() {},
after: function() {},
route: function(route, name, callback) {
Backbone.history || (Backbone.history = new Backbone.History);
if (!_.isRegExp(route)) route = this._routeToRegExp(route);
if (!callback) callback = this[name];
Backbone.history.route(route, _.bind(function(fragment) {
var that = this;
var args = this._extractParameters(route, fragment);
if (_(this.before).isFunction()) {
this.before.apply(this, args);
}
if (callback) callback.apply(that, args);
if (_(this.after).isFunction()) {
this.after.apply(this, args);
}
}, this));
}
});
}
//Add the extend method to this modules public methods
return {
extend: extend
};
});
//Some other app init file
define(['backbone', 'utils/routerExtend'], function(Backbone, routerExtend) {
//Extend router
routerExtend.extend.call(this);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment