Create a callback function within a custom jQuery function

Posted by Thomas on Stack Overflow See other posts from Stack Overflow or by Thomas
Published on 2012-03-26T23:17:19Z Indexed on 2012/03/26 23:29 UTC
Read the original article Hit count: 220

Filed under:

I'm not sure how to approach this as I am fairly new to jQuery. I'm wanting to create a callback function within a custom function. Here's my example:

function doSomething() {
    var output = 'output here';
    // Do something here

    // This is where I want to create the callback function and pass output as a parameter
}

I want the callback function to be accessible by any number of scripts (e.g. more than one script can access this callback).

This function (doSomething) is not part of a plugin but rather part of another callback function itself. I've also created a var within the function and want to pass that through the callback function as well.

How can I do this?

© Stack Overflow or respective owner

Related posts about jQuery