Created
June 13, 2013 16:38
-
-
Save phamann/5775264 to your computer and use it in GitHub Desktop.
Require.js for ben
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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