Skip to content

Instantly share code, notes, and snippets.

@gbabiars
Last active December 19, 2015 09:48
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 gbabiars/5935257 to your computer and use it in GitHub Desktop.
Save gbabiars/5935257 to your computer and use it in GitHub Desktop.
Examples of how to create Backbone view classes with mixins.
var mixin1, mixin2, mixinArray;
mixin1 = {
something: function() {
return 'something';
}
};
mixin2 = {
another: function() {
return 'another';
}
};
mixinArray = [mixin2, mixin1];
// view class with one mixin
var ViewWithOneMixin = Backbone.View.extendWithMixin(mixin1, {
// view specific properties and methods
});
// view class with two mixins, mixin1 will override any conflicts on mixin2
var ViewWithTwoMixins = Backbone.View.extendWithMixin(mixin2, mixin1, {
// view specific properties and methods
});
// view class with mixin array, mixin1 will override any conflicts on mixin2
var ViewWithMixinArray = Backbone.View.extendWithMixin(mixinArray, {
// view specific properties and methods
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment