Skip to content

Instantly share code, notes, and snippets.

@JasonOffutt
Created September 16, 2013 17:16
Show Gist options
  • Save JasonOffutt/6583614 to your computer and use it in GitHub Desktop.
Save JasonOffutt/6583614 to your computer and use it in GitHub Desktop.
Adding Backbone.js extensions to a Require.js project.
define(['backbone'], function (Backbone) {
return {
init: function () {
Backbone.View.prototype.close = function () {
this.remove();
this.unbind();
if (typeof this.onClose === 'function') {
this.onClose();
}
};
}
}
});
(function () {
require.config({
paths: {
backbone: 'path/to/backbone.min.js',
underscore: 'path/to/underscore.min.js',
jquery: 'path/to/jquery.min.js',
extensions: 'path/to/extensions.js'
},
shim: {
underscore: {
deps: [],
exports: '_'
},
jquery: {
deps: [],
exports: '$'
},
backbone: {
deps: [ 'underscore', 'jquery' ],
exports: 'Backbone'
}
},
callback: function () {
require([ 'underscore', 'backbone', 'jquery', 'extensions' ], function (_, Backbone, $, ext) {
// Call `init` to add the `close` method to Backbone.View
ext.init();
// Do all the other stuff you need to do here. Fetch data, set up router,
// start Backbone history, etc.
});
}
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment