<1>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><!-- C#匿名函数--><title></title><script type="text/javascript">var f1 = function (x, y) { //【1】 定义一个匿名函数,用变量f1来指向它(f1相当于一个托付,这个时候f1就能够当做一个函数来用了)return x + y;}//调用这个匿名函数alert(f1(5, 6)); //输出11//【2】 还可声明匿名函数马上使用alert(function (a, b) { return a + b } (10, 2)); //直接声明一个匿名函数function (a, b) { return a + b },然后直接使用function (a, b) { return a + b } (10, 2)。连指向匿名函数function (a, b) { return a + b }的变量f1都不用了。这里输出12//【3】 没有參数的匿名函数var f2 = function () { alert("你好") };f2(); //这里输出“你好”var f3 = function () { return 5 };alert( f3() + 5) //输出10
;</script>
</head>
<body></body>
</html>