<html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- C# anonymous function--> <title></title> <script type="text/javascript"> var f1 = function (x, y) { //【1】 Define an anonymous function and point it to it with the variable f1 (f1 is equivalent a un delegado, y F1 se puede usar como una función) return x + y; } // Llame a esta alerta de función anónima (F1 (5, 6)); // Salida 11 // 【2】 También puede declarar que la función anónima usa inmediatamente alerta (función (a, b) {return a + b} (10, 2)); // declara directamente una función anónima (a, b) {return a + b}, y luego use directamente la función (a, b) {return a + b} (10, 2). Incluso la variable F1 apuntando a la función de función anónima (a, b) {return a + b} no es necesaria. Aquí la salida 12 // 【3】 Función anónima var f2 sin parámetros var f2 = function () {alert ("hola")}; f2 (); // Salida "Hello" var f3 = function () {return 5}; alerta (f3 () + 5); // Salida 10 </script> </head> <body> </body> </html>