EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on May 10, 2013, 03:33:53 AM



Title: appending multiple functions to events
Post by: devnull on May 10, 2013, 03:33:53 AM
How can I append multiple functions to an event, such that they are appended to and don't overwrite the previous function.

Code:
cbo.combobox('options').onSelect = function(){ functionA();};

if( x==y) cbo.combobox('options').onSelect += function(){ functionB();};


Title: Re: appending multiple functions to events
Post by: stworthy on May 10, 2013, 07:35:15 AM
Here is the simple solution to achieve this functionality.
Code:
	function CB(){
this.ff = [];
this.onSelect = (function(){
var ff = this.ff;
return function(row){
for(var i=0; i<ff.length; i++){
ff[i].call(this,row);
}
}
}).call(this);
};
CB.prototype.add = function(f){
this.ff.push(f);
};
var cb = new CB();
cb.add(function(row){
console.log('function1:'+row);
});
cb.add(function(row){
console.log('function2:'+row);
});
Code:
	cbo.combobox('options').onSelect = cb.onSelect;