Callback functions are able to accept some parameters, but they are not explicitly declared when calling the function.
How does this actually work? What is going on that allows us to pass a function as a parameter to another function, and implicitly include a parameter in there?
For example:
Javascript
$.get('somefile.php', {func : 'getUserNames'}).done(function(data){
if(data)
console.log(data); // '{"0" : "billy", "1" : "bobby"}'
// This is a js ajax call to a php file.
// How exactly am I retrieving "data" ?
}, 'json');
C#
private void BeginReadingData(){
NetworkStream stream = tcpClient.GetStream();
stream.BeginRead(buffer, 0, bufferSize, MyCallBack, tcpClient);
}
private void MyCallBack(IAsyncResult ar){
// Now I can operate on 'ar'
// why and how?
}
This is something I understand how to use, just not how to explain or correctly describe the process.