日期:2014-05-16 浏览次数:20646 次
$.fn.youName = (function(){
function selfEvent(el,event,callback){
this.event = {};
selfEvent.EL[el] = this;
this.on(el,event,callback);
}
selfEvent.prototype.on = function(el,event,callback){
this.event[event] = function(){
callback.apply(el,arguments);
}
}
selfEvent.prototype.fire = function(el,event,args){
this.event[event].call(el,args);
}
selfEvent.EL= {};
return function(event,argsOrCallBack){
$(this).each(function(){
var isBind = typeof argsOrCallBack === 'function';
if(isBind){
new selfEvent(this,event,argsOrCallBack)
}else{
selfEvent.EL[this].fire(this,event,argsOrCallBack);
}
});
}
})();
$('body').youName('test',function(data){
console.log(data)
});//绑定事件test
$('body').youName('test',[1,2,3,4])//触发test事件,参数为[1,2,3,4]