I’m on my way to learning more about javascript and it could get really confusing at most times.
So we have this in jQuery:
$.getJSON('getDate.php', function(response, status, xhr) { ... });
And this:
$('a').click(function(event) { ... });
Based on the code above and in terms of javascript definitions, please consider these arguments(response, status, xhr & event) and the questions about them as listed below:
- What are they exactly?
- Where do they come from?
- When do you actually use them?
- What’s the proper way of using them?
I’m a newbie programmer and I’m not sure if I asked the right questions.
Thanks.
They are parameters that will be provided to your function at the time it is invoked. Note that the names are not significant, but the ordering is.
They come from the calling code. In this case, that would be jQuery. It will set up the appropriate values for these parameters and pass them to your function(s) at invocation time.
When you need/want to. Check the jQuery documentation for details on exactly what information each parameter contains. That will give you a better idea on when you might want to do something with a given parameter.
Just refer to them by name in your function code (i.e. the stuff between
{and}). They work the same as any other variable in JavaScript. Refer to the jQuery documentation for a list of fields that are available on each different parameter.