How does this code sample differ from a normal function declaration paired with an if statement for the event trigger? Is brevity the only advantage?
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
In Javascript you may have what is called an anonymous function. In the above code, the anonymous function will be executed when the xmlhttp.onreadystatechange event is fired. Other examples are:
Or you could create an anonymous variable-function…