Martin Honnen wrote:
maya wrote:
I know how to create functions, call functions, pass vars to
functions, etc.. but what I don't quite get yet is this syntax..
http_request.onreadystatechange = function(){
Functions are first class citizens in JavaScript so the same way you can
write expressions to yield string or number or boolean values you can
write an expression that yields a function. So
function () { }
on the right hand side of the assignment is a function expression that
yields an anonymous function object as its result.
thank you Martin.. so how do you use this "anonymous function object"...
I'm looking at JavaScript Bible; this is entire explanation he gives
of this technique:
One last function creation format is available in NN4+. This advanced
technique, called a lambda expression, provides a shortcut for creating
a reference to an anonymous function (truly anonymous because the
function has no name that you can reference later). The common
application of this technique is to assign function references to event
handlers when the NN event object also must be passed. The following is
an example of how to assign an anonymous function to an onChange event
handler for a form control:
document.forms[0].age.onchange = function(event)
{isNumber(document.forms[0].age)}
I still don't get what he's doing here.. (would this be the same as
declaring
function isNumber() { // etc...}
(maybe passing it some params..)
in other words is this an alternative way of declaring a function.. or
is it something different altogether..
(does he mean like anomymous classes in Java.. I know Java, but find
anonymous classes confusing...)
thank you..