Skip to content

Instantly share code, notes, and snippets.

@slashdotdash
Forked from dmitry/backbone-mixin.js
Created November 25, 2013 10:56
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 slashdotdash/7639655 to your computer and use it in GitHub Desktop.
Save slashdotdash/7639655 to your computer and use it in GitHub Desktop.
/**
* ## Merging mixin views in backbone.js ##
*
* really just more a test for tumblr gistr
*/
/**
* Merge the mixin (a Backbone.View) into another Backbone.View. Automatically merge events, defaults, and call the parent initializer.
**/
function mergeMixin(view, mixin) {
_.defaults(view.prototype, mixin);
_.defaults(view.prototype.events, mixin.events);
if (mixin.initialize !== undefined) {
var oldInitialize = view.prototype.initialize;
view.prototype.initialize = function () { mixin.initialize.apply(this); oldInitialize.apply(this); };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment