Closed russplaysguitar closed 7 years ago
Example failing test:
it('should serialize model using multiple mixins with toJSON calls', function () {
var OtherMixin = {
toJSON: function() {
return this.constructor.__super__.toJSON.apply(this, arguments);
}
};
var MultipleMixinModel = Backbone.Model.extend({
toJSON: function() {
return { foo: 'bar' };
}
}).extend(OtherMixin).extend(NestedTypeMixin);
var multipleMixinModel = new MultipleMixinModel();
// act
var actual = multipleMixinModel.toJSON();
expect(actual).to.eql({ foo: 'bar' });
});
If you try to use an additional model mixin with this mixin which also overrides
toJSON
and callsthis.constructor.__super__.toJSON.apply(this, arguments);
, an infinite loop occurs due to the nested type mixin callingtoJSON
with the child context.A rough way to fix this in the nested types mixin would be something like: