函數定義的三種方式

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
<title>無標題文檔</title>  
</head>  
  
<body>  
    <script>  
        /* 
         *函數定義的一種方式  
        */  
        function aa(){  
            document.write("aaaa");  
        }  
          
    </script>  
    <!--<button name="hanshu" οnclick="aa()">按鈕</button> -->  
    <input type="button" value="按鈕" οnclick="aa()" />  
    <script>  
        /* 
        * 函數定義的一種方式之二 
        */  
        var aa2 = function(a,b){  
            return a*b;  
        }  
        alert(aa2(4,5));  
    </script>  
      
    <script>  
        /* 
        *   構造函數定義JavaScript函數,注意Function中的F是大寫 
        */  
        var add = new Function('a','b','return a+b;');  
        //調用上面定義的add函數  
        var sum = add(3,4);  
        alert(sum);  
    </script>  
      
</body>  
</html>  

可以有返回值,可以用變量來接受其返回值

 如果沒有return,則返回undefined.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章