In the following code, I hold my variables t and hoverCalled in a closure scope. Would the performance be better if I held them in jQuery.data properties? I have heard that creating closure scopes is a bit expensive in terms of performance. However, I don't know if it worse than the alternatives.
hoverDelay = function(hoverIn,hoverOut) {
var t=null;
var hoverCalled=false;
return {
hoverIn:function() {
t = setTimeout(function() {
//$(self).data('hoverCalled',true);
hoverCalled=true;
hoverIn();
}, 500);
$(this).data('timeout', t);
},
hoverOut:function() {
if (hoverCalled){
hoverOut();
hoverCalled=false;
} else {
//var t=$(self).data('timeout');
//clearTimeout($(this).data('timeout'));
t&&clearTimeout(t);
}
}
};
};