A few nice snippets around backbone that are not big enough to deserve their own plugin
The plugin itself implements the Universal Module Definition (UMD). You can use it with a CommonJS like loader, or with an AMD loader or via vanilla javascript.
The plugin has two dependencies, underscore.js and backbone.js
You can directly download the Development Version or the Production Version from the root folder
$ volo add Backbone.Utils
$ bower install backbone.utils
$ jam install Backbone.Utils
$ npm install Backbone.Utils
// AMD
require(['underscore', 'backbone', 'path/to/backbone.utils'], function (_, Backbone, Utils) {
/* Do stuff with Backbone here */
});
// CommonJS
var _ = require('underscore');
var Backbone = require('backbone');
var Utils = require('backbone.utils');
<!-- Vanilla javascript -->
<script src="path/to/underscore.js"></script>
<script src="path/to/backbone.js"></script>
<script src="path/to/backbone.utils.js"></script>
<script>
console.log(Backbone.Utils); // Backbone and the Utils property are globals
</script>
Soft Extend Enables you to extend ressources like object literals, so you can do now smth. like this:
var Parent = Backbone.Model.extend({
params: {
foo: 'bar',
bar: 'foo'
}
});
var Child = Parent.softExtend(['params'], {
params: {
bar: 'I´ve got softly extended',
baz: 'I´am new!'
}
});
// State of params in 'Child'
var child = new Child();
console.log(child.params);
// {
// foo: 'bar',
// bar: 'I´ve got softly extended',
// baz: 'I´am new!'
// }