Skip to content

Instantly share code, notes, and snippets.

@dmitry
Forked from wesen/backbone-mixin.js
Created October 1, 2011 21:49
Show Gist options
  • Save dmitry/1256695 to your computer and use it in GitHub Desktop.
Save dmitry/1256695 to your computer and use it in GitHub Desktop.
Merge backbone views (mixin pattern)
/**
* ## 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); };
}
}
@hxgdzyuyi
Copy link

cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment