Skip to content

Instantly share code, notes, and snippets.

Created February 7, 2012 16:19
Show Gist options
  • Save anonymous/1760508 to your computer and use it in GitHub Desktop.
Save anonymous/1760508 to your computer and use it in GitHub Desktop.
Backbone ViewFactory
var ViewFactory = (function() {
function ViewFactory() {
this.eventBus = _.extend({}, Backbone.Events);
this.registry = {
factory: this
};
}
ViewFactory.prototype.register = function(key, value) {
return this.registry[key] = value;
};
ViewFactory.prototype.create = function(ViewClass, options) {
var klass, passedOptions;
options = options || {};
passedOptions = _.extend(options, this.registry, {
pubSub: this.pubSub
});
klass = ViewClass;
klass.prototype.eventBus = this.eventBus;
return new klass(passedOptions);
};
return ViewFactory;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment