I am wondering if the methods associated with the events are called asynchronously or not in javascript? In my case, I use Backbone.js to create the application. I use an event aggregator to communicate between views.
If I have a method that fires an event, will methods be fired in other views associated with this event before the rest of the method that raises the trigger event is fired?
The event aggregator is as follows:
var eventAggrigator = _.extend({}, Backbone.Events); eventAggrigator.on('submitContactEditForm', function() { console.log('Contact edit form submit event triggered'); });
Function call that raises the event (this function is called from ViewA):
saveContact: function(event) { var self = this;
The ViewB is attached to the event 'submitContactEditForm' (see the corresponding code from the ViewB below):
initialize: function() { _.bindAll(this, 'addSortableFields', 'appendNewField', 'getFieldsHtml', 'removeField', 'render', 'setEmailValues');
So the question will be, will ViewB.setEmailValues () always execute before this.model.save () in ViewA.saveContact () is executed?
source share