> I'm thinking about extending the callback system in the Tabs plugin to 
> not only allow one callback, but different ones for more flexibility:
> 
> onActivate (invoked on click), onHide (invoked after old tab got 
> hidden), onShow (invoked after new tab is revealed == callback as is now).
> 
> First question: Does that make sense at all?

I now sure if someone really gains anything when providing the callback to the 
tabs plugin instead of simply binding to the click event directly.

> If yes, the way it is now is that the callback function is called with 
> the scope of the tab container (the div) that gets revealed and two 
> arguments which the first could also be referred to with "this" obviously:
> 
> settings.callback.apply(toShow[0], [toShow[0], toHide[0]]);
> 
> Seems redundant to me. The only advantage I see here is that I could 
> define a function without arguments if I only need to refer (via "this") 
> to the tab that gets shown.
> 
> Wouldn't it be more reasonable to have "this" being the tab that was 
> clicked?
> 
> settings.callback.apply(clicked, [toShow[0], toHide[0]]);

Please: Just call the callback without modifying it's scope. Pass everything 
necessary as arguments and nothing more. You win to prizes at once: It's 
easiert to simply document and understand the arguments, instead of "and it is 
called in the scope of the clicked element". And you can use a method of a 
class as the callback. When the scope is untouched, the object can access other 
members or methods of itself, avoiding unecessary closures.

A small example:

var handler = function() {
  this.stuff = {};
};
handler.prototype.handleEvent = function(element, event) {
  // save the elements name via the event type
  this.stuff[event.type] = element.name;
};

This isn't possible when "this" refers to the current element.

Actually I'd prefer that jQuery worked the same way, saving me lots of trouble. 
It wouldn't hurt to simply pass the scope as an argument. It may be too late to 
change that for jQuery, but at least it shouldn't be used in plugins.

--
Jörn Zaefferer

http://bassistance.de
-- 
"Ein Herz für Kinder" - Ihre Spende hilft! Aktion: www.deutschlandsegelt.de
Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's Cup-Yacht!

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to