Permalink
Browse files

Merge pull request #20 from jridgewell/extend

Use Backbone's native `.extend` for defining `Support.CompositeView` and `Support.SwappingRouter`.
  • Loading branch information...
2 parents 4d36dc6 + 710dc3f commit 06d971593c92a55bc4af73f4c22746a70055ee25 @ecbypi ecbypi committed Mar 18, 2015
@@ -1,9 +1,9 @@
-Support.CompositeView = function(options) {
- this.children = _([]);
- Backbone.View.apply(this, [options]);
-};
+Support.CompositeView = Backbone.View.extend({
+ constructor: function(options) {
+ this.children = _([]);
+ Backbone.View.call(this, options);
+ },
-_.extend(Support.CompositeView.prototype, Backbone.View.prototype, Support.Observer.prototype, {
leave: function() {
this.trigger('leave');
this.unbind();
@@ -66,4 +66,4 @@ _.extend(Support.CompositeView.prototype, Backbone.View.prototype, Support.Obser
}
});
-Support.CompositeView.extend = Backbone.View.extend;
+_.extend(Support.CompositeView.prototype, Support.Observer.prototype);
@@ -1,8 +1,4 @@
-Support.SwappingRouter = function(options) {
- Backbone.Router.apply(this, [options]);
-};
-
-_.extend(Support.SwappingRouter.prototype, Backbone.Router.prototype, {
+Support.SwappingRouter = Backbone.Router.extend({
swap: function(newView) {
if (this.currentView && this.currentView.leave) {
this.currentView.leave();
@@ -16,5 +12,3 @@ _.extend(Support.SwappingRouter.prototype, Backbone.Router.prototype, {
}
}
});
-
-Support.SwappingRouter.extend = Backbone.Router.extend;
@@ -262,4 +262,11 @@ describe("Support.CompositeView", function() {
expect(eventListener.called).toBeTruthy();
});
});
+
+ describe("class", function() {
+ it("respects instanceof", function() {
+ var view = new Support.CompositeView;
+ expect(view instanceof Backbone.View).toBeTruthy();
+ })
+ });
});
@@ -116,4 +116,8 @@ describe("Support.SwappingRouter", function() {
done();
});
});
+
+ it("is instanceof Router", function() {
+ expect(router instanceof Backbone.Router).toBeTruthy();
+ });
});

0 comments on commit 06d9715

Please sign in to comment.