欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript匿名函數(shù)與委托使用示例

 更新時間:2014年07月22日 15:48:45   投稿:whsnow  
本例主要介紹了JavaScript匿名函數(shù)與委托的使用,需要的朋友可以參考下
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
  <!-- C#匿名函數(shù)--> 
  <title></title> 
  <script type="text/javascript"> 
    var f1 = function (x, y) { //【1】 定義一個匿名函數(shù),用變量f1來指向它(f1相當于一個委托,這個時候f1就可以當做一個函數(shù)來用了)  
      return x + y; 
    } 
 
    //調(diào)用這個匿名函數(shù)  
    alert(f1(5, 6)); //輸出11  
    //【2】 還可聲明匿名函數(shù)立即使用  
    alert(function (a, b) { return a + b } (10, 2)); //直接聲明一個匿名函數(shù)function (a, b) { return a + b },然后直接使用function (a, b) { return a + b } (10, 2)。連指向匿名函數(shù)function (a, b) { return a + b }的變量f1都不用了。這里輸出12  
 
    //【3】 沒有參數(shù)的匿名函數(shù)  
    var f2 = function () { alert("你好") }; 
    f2(); //這里輸出“你好”  
 
    var f3 = function () { return 5 }; 
    alert( f3() + 5);//輸出10 
  </script> 
</head> 
<body> 
 
</body> 
</html>

相關文章

最新評論