[jQuery] msie closures syntax

[jQuery] msie closures syntax

"this" doesn't work like a local variable. Inside a nested function, "this"
is not the same as in the outer function. That's what is messing things up.
If I understand your code, you can write it more simply like this:
(function($) {
$.fn.Tooltip = function(settings) {
var $all = this;
settings = $.extend($.extend({}, arguments.callee.defaults),
settings || {});
$all.filter('[@title]').bind( settings.event, onmouseover );
return this;

function onmouseover( event ) {
//...
setTimeout(
function() {
on( $all.attr('id'), $all.attr('ttbody'),
event.pageX + settings.xoffset,
event.pageY + settings.yoffset
);
}, settings.ondelay );
//...
}

function on( mysrcid, body, x, y ) {
// do stuff...
}
};
})(jQuery);
But now that it's simple enough for me to understand, one question comes to
mind: Do you use this plugin only with a single element, e.g.
$('#foo').Tooltip(), or can it use multiple elements, e.g.
$('.foo').Tooltip()? The two attr() calls inside the setTimeout don't look
right for multple elements.
-Mike
































    • Topic Participants

    • mike