Created
September 16, 2013 17:16
-
-
Save JasonOffutt/6583614 to your computer and use it in GitHub Desktop.
Adding Backbone.js extensions to a Require.js project.
This file contains hidden or 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
define(['backbone'], function (Backbone) { | |
return { | |
init: function () { | |
Backbone.View.prototype.close = function () { | |
this.remove(); | |
this.unbind(); | |
if (typeof this.onClose === 'function') { | |
this.onClose(); | |
} | |
}; | |
} | |
} | |
}); |
This file contains hidden or 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
(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