I'm working with backbone.js building some complex view relationships, and I'm wondering if there are any problems from a javascript performance standpoint of doing something that looks like this:
var viewOne = Backbone.View.extend({
tagName : 'li',
initialize : function() {
this.v2 = new viewTwo({parent:this});
},
clickHideOne : function() {
$(this.el).removeClass('selected');
}
});
var viewTwo = Backbone.View.extend({
tagName : 'a',
initialize : function() {
this.bind('click', this.clickHide, this);
},
clickHide(){
$(this.el).removeClass('selected');
this.options.parent.clickHideOne();
}
});
Where this is a very simple example of a circular reference between two views, in order to have events in one view easily propagate up a chain of views, or maintain any references to objects in the parent views. Are there any situations where this would be a problem, specifically in relation to the potential leaks with DOM element references in IE7+, or is there another recommended best practice for referencing parent views.
Also, I understand that I could just do $(this.el).parent('li').removeClass('selected'); in viewTwo, that's not the point... this just a very simple example of the question I have about the circular reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With