Hola, estoy queriendo aprender a usar YUI, y en un ejemplo me encuentro con
esto:
<script>
(function() {
//A function that pops up a "Hello World" alert:
var helloWorld = function(e) {
YAHOO.log("helloWorld function firing.", "info", "example");
alert("Hello World!");
}
//subscribe the helloWorld function as an event
//handler for the click event on the container
//div:
YAHOO.util.Event.addListener("container", "click", helloWorld);
//A function that pops up an alert and
//prevents the default behavior of the event
//for which it is a handler:
var interceptLink = function(e) {
YAHOO.util.Event.preventDefault(e);
YAHOO.log("You clicked on the second YUI link.", "info", "example");
alert("You clicked on the second YUI link.");
}
//subscribe our interceptLink function
//as a click handler for the second anchor
//element:
YAHOO.util.Event.addListener("secondA", "click", interceptLink);
//log message to indicate that the example is ready:
YAHOO.log("When you begin interacting with the example at left, you'll
see log messages appear here.", "info", "example");
})();
</script>
Yo estoy aprendiendo Javascript, pero hasta ahora nunca vi este tipo de
contrucciones.
Que significa asignar funciones anonimas a variables, y todas ellas dentro
de dos parejas de parentesis ()() ?
Creo que la estructura aproximada de ese ejemplo es asi:
( function()
{
var xxx = function() { codigo }
var yyy = function() { codigo }
yahoo.llamadafuncion();
}
) ();
Con que se come ? Digo, como se le llama a este tipo de construcciones en JS
y porque los ejemplos de YUI
lo usan, en lugar de usar el modelo mas 'tradicional' de una funcion debajo
de otra ?
Gracias.
_______________________________________________
Lista de correo Programacion.
[email protected]
http://listas.fi.uba.ar/mailman/listinfo/programacion