函数传参的具体用法

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            //参数 = js的数据类型(基本类型和引用类型)
            //数字.字符串.布尔.函数.对象.未定义.数组
            fnc(100);
            fnc('stlying');
            fnc(function() {
                alert(222);
            });
            function fnc(e) {
                if(typeof e === 'number' && e === e) {
                    alert(e + 5)
                } else if(typeof e === 'string') {
                    alert(e.charAt(3))
                } else if(typeof e === 'function') {
                    e();
                }
            }            
            //例子
            fun(window,document);
            function fun(win,doc){
                win.onload = function(){
                    doc.body.innerHTML ="你好,js";
                }        
            }
            //return返回值
            alert(fn())  //return ==>等价于fn()==>100
            function fn(){
                return 100
            }
            //传的参数只能一一对应
        </script>
    </body>
</html>

 

posted @ 2017-09-24 21:39  鱼樱前端  阅读(235)  评论(0编辑  收藏  举报