views:

374

answers:

1

Hi all,
I'm using the hoverIntent Jquery plugin and I have a question regarding callback functions.

In one of my previous questions, it was pointed out that I should use function pointers for the callbacks.

My question is this: how do I pass parameters to the function pointers then?

function initHoverHandler(type) {
   var config = {
      over: overHandler, // This is the issue, how do I pass var type to overHandler
      out: hideHandler
   };

$(this).hoverIntent(config);
};
function overHandler(type) {
    alert(type); // shows [object Object]

};
+2  A: 
over: function(){
         overHandler( type );
      }

Another way is to use a closure

 over: overHandler( type );  

function overHandler( ) {

  return function(type) {

      alert(type);

  }

};
redsquare
Does this defeat the purpose of passing a reference in the first place?
Michael
yup, see closure way
redsquare