Model.pototype={add:function(){.....// at the endthis.fireEvent('add')}on:function(event,handler,scope,options){if(this.hasEvent(event)){vare=newEvent(handler,scope,options);if(!this.listener[event]){this.listener[event]=newArray();}this.listener[event].push(e);}},//privatefireEvent:function(event){if(this.hasEvent(event)){for(vari=0;i<this.listener[event].length;i++){vare=this.listener[event][i];e.handler.call(e.scope,options)}}},//privatehasEvent:function(event){for(vari=0;i<this.event.length;i++){if(this.event[i]==event){returntrue;}}returnfalse;}}
functionView(model){this.model=model;}varmodel=newModel();varview=newView(model);view.addView=function(){//something for handle while model fire.....};view.addHandler=function(){this.model.on('add',addView,this);};view.addHandler();