And to correct myself, my system didn't do that and it will not do that. 
In fact the arguments sent into the trigger call have precedence and in 
retrospect that makes some semblance of sense to me. So my below trigger 
example actually does this:

$().trigger('click',arg5,arg6);
// fn1 runs with args [event,arg5,arg6,arg1,arg2]
// fn2 runs with args [event,arg5,arg6,arg3,arg4]

NB. My system doesn't actually do that... I thought I had rewritten that 
section but I hadn't. I will later today but for now I'm off to lectures...

-blair


Blair Mitchelmore wrote:
> Well hello right back Jörn!
>
> Jörn Zaefferer wrote:
>> Hi Blair!
>>
>>> Since this has come up again, I thought I'd mention - despite my distate 
>>> for plugin pimping - my own event++ system ( 
>>> http://jquery.offput.ca/event++ ) I wrote which could be used as the new 
>>> system. It can handle additional arguments sent to the event simply by 
>>> adding arguments to the event bind function call. It can also handle 
>>> limiting the number of event occurrence to run but as the first argument 
>>> to bind, click, et. al. It also handles scope arbitration using the 
>>> final argument provided to the event bind function call. There's a 
>>> little more detail available at the link above but regardless it seems 
>>> like it's a system people would appreciate and it barely adds any code 
>>> complexity to the current system.
>> Thanks, I'll keep that in mind.
>>
>> It looks like there were some changes to the event system since you wrote 
>> your system, we have to be careful with those.
>>
>> The additonal scope looks interesting, but rather useless. Do you have an 
>> example where that is really helping instead of only brain-twisting?
>>
>> Please don't get me wrong, but that scope seems to be way too geeky.
>>
>> By the way: We could simply allow Arrays and Objects for additonal argument: 
>> If it is a number, it's the amount of events to handle, otherwise its a 
>> pass-through argument.
>>
>> Remains the question on how to actualy pass the additonal stuff, because:
>> var x = $(...).bind("click", handler, args);
>> x.trigger("click", moreArgs);
>>
>> How to write the handler?
>>
>> var handler = function(event, bind, trigger) {
>>   // do something with bind and trigger, we have to list bind also when 
>> using only trigger
>> };
>>
>> var handler = function(event) {
>>   // do something with event.bind and event.trigger, they contain the data 
>> passed to bind and trigger, if any
>> };
>>
>> I'd prefer the second approach. Documenting callback parameters is difficult 
>> anyway.
>>
>> --
>> Jörn Zaefferer
>>
>> http://bassistance.de
> Yeah scope modification is really only useful when you're writing a 
> large object oriented system and you are writing event functions within 
> the object that is using it and want to write the code using 'this' to 
> make it explicit that you are referencing the object. I agree it's very 
> rare for most web development but including in the system wouldn't be 
> much of a bother and it would be a boon for OO obsessed coders out there.
>
> The way I coded the trigger and handle functions in my system it worked 
> like this (or at least it should. This is untested but theoretically 
> sound and the way I intended for it to work).
>
> $().click(fn1,arg1,arg2);
> $().click(fn2,arg3,arg4);
> // someone clicks there
> // fn1 runs with arguments [event,arg1,arg2]
> // fn2 runs with args [event,arg3,arg4]
> $().trigger('click');
> // fn1 runs with args [event,arg1,arg2]
> // fn2 runs with args [event,arg3,arg4]
> $().trigger('click',arg5,arg6);
> // fn1 runs with args [event,arg1,arg2,arg5,arg6]
> // fn2 runs with args [event,arg3,arg4,arg5,arg6]
>
> To me this is the least surprising result, would you agree?
>
> -blair

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to