Created
February 7, 2012 16:19
-
-
Save anonymous/1760508 to your computer and use it in GitHub Desktop.
Backbone ViewFactory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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