[thelist] [JS] window.onload is a liar...

Marcus Andersson marcus at bristav.se
Tue Mar 16 08:31:35 CST 2004


> The anon function does not evaluate and return like a named
> function would. Have I understood you correctly?
> 

This isn't true (the parts before were).

Consider the following case:

var a = new Object();

a.aMethod = function() {
   return "hello";
}

alert(a.aMethod());

If you run the example you'll see that a.aMethod evaluates and returns a 
value just as a "normal" function (an anonymous function is a "normal" 
function as well, you just don't have the same means to reference it).

Event handlers can also return values. It can sometimes be useful for 
event handlers to return values but the only value that is interesting 
in that case is false. If you return a false value the event bubbling 
will stop (this should be handled with cancelBubble on the event object 
these days...)

/Marcus





More information about the thelist mailing list