I would like to be able to pass a parameter in a callback, but from the original calling function, and with the stipulation below, e.g. given:
function foo() {
var p = 5;
getDataFromServer(callBackFunction);
}
function callBackFunction(data) {
// I need value of 'p' here
...
}
function getDataFromServer(callback) {
// gets data from server
callback.call();
}
The catch is that I don’t want to change the function getDataFromServer(), (i.e. allowing it to accept another parameter.)
Is this possible? Thanks.
Yes, and this is good to know.