Pass parameters to Javascript callback functions -



Pass parameters to Javascript callback functions -

this have:

function populateelement(arg1) { getdata(arg1); } function getdata(query) { var url = "http://foo" + query + "&callback=processdata"; // stuff } function processdata(results) { callbackforgetdata(results); } function callbackforgetdata(result) { // process info }

i want pass 2 more arguments function populateelement so:

function populateelement(arg1, arg2, arg3) { getdata(arg1); }

and have arg2, arg3 available in callbackforgetdata

function callbackforgetdata(result) { // process info // utilize arg2, arg3 here }

how should this?

you can pass them on callback , access them in arguments array

function getdata(result) { //result === arg1 //arguments[0] === arg1 //arguments[1] === arg2 //arguments[2] === arg3 //and on } getdata(arg1, arg2, arg3);

javascript callback parameter-passing

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -