Pass a function as parameter in jQuery?

Posted by thedp on Stack Overflow See other posts from Stack Overflow or by thedp
Published on 2010-04-17T20:52:57Z Indexed on 2010/04/17 21:03 UTC
Read the original article Hit count: 255

Hello,

I would like to pass to a jQuery function a regular function, instead of the usual anonymous function, but I'm not sure how such a thing could be done.

Instead of this:

function setVersion(feature) {
      $.post("some.php", { abc:"abc" },
      function(data){
         // do something here
      }, "json");
}

I would like to do this:

function foo(data){
   // do something here
}

function setVersion(feature) {
      $.post("some.php", { abc:"abc" }, foo, "json");
}

Thank you.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript