one of my co-workers reviewed my code in javascript and told me that I should not use a view in a controller. Instead, I should use a mediator. I'm totally lost. He will not be available until next week so here I am.
In my applications, I initialize a view in a controller (pseudo code) like below.
var controller = (function(){
return {
init: function()
{
this.view = new View("template");
this.view.render();
}
}
})();
I have no idea how I separate a view from a controller and use mediator to work with them.
could anyone please give me an idea or a sample code or concept?
First of all a bit on roles of Ms, Vs & Cs in a MVC pattern:
The three parts:
Model
-View-Controller:Model-
View
-Controller:Model-View-
Controller
:What your co-worker is trying to tell you is this:
The below pic is a Sequence Flow(an approximate) pertaining to Zend framework, which is a MVC framework for PHP.
Click here for a bigger image.

Observe the Dispatcher (3rd from last) in the above diagram.
Lets consider only the following for your case:
What you will have to do is this:
If the View has to trigger an event, it will not handle the event by itself. It will dispatch the event to the Dispatcher along with the parameters (if any) for the event.
The Dispatcher will now
The controller will now:
The Dispatcher will now:
The View will now:
Why so much needs to be done?
To keep the roles segregated and clear
.