I am new to Backbone.js. I have this project where there is a hierarchy of multiple views and sometimes the views need to communicate with each other. After a little research on the Internet, I came across https://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/ and tried to use the event aggregator.
However, it didn't work. My guess is that the 'vent' is not the same instance across all the views. So, if there is any way to definine it as a static variable, I can probably make it work. So, is there a way to define static variables in Backbone.js?
Yes, it is possible to add static variables to any Backbone objects using extend:
obj.extend( protoProps, staticProps );
e.g.:
var MyView = Backbone.View.extend( { events: ... }, {
myStaticVar: 'anything'
} );
...
var value = MyView.myStaticVar;
However, I am not sure you need this in this case.
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