Pass Extra Parameters to JavaScript Callback Function

Posted by BRADINO on Bradino See other posts from Bradino or by BRADINO
Published on Sat, 10 Oct 2009 20:49:03 +0000 Indexed on 2010/03/23 5:22 UTC
Read the original article Hit count: 550

Filed under:

Here is a simple example of a function that takes a callback function as a parameter.

query.send(handleQueryResponse);

function handleQueryResponse(response){

     alert('Processing...');

}

If you wanted to pass extra variables to the callback function, you can do it like this.

var param1 = 'something';

var param2 ='something else';

query.send(function(response) { handleQueryResponse(response, param1, param2) });

function handleQueryResponse(response,param1,param2){

     alert('Processing...');

     alert(param1);

     alert(param2);

}

© Bradino or respective owner

Related posts about JavaScript