JavaScript中函数带与不带括号的区别

<!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>
    <title></title>
    <script type="text/javascript">
        function f() {
            alert('我是f函数');
            return 1;
        }
        var v1 = f(); //将函数f()的返回值赋值给v1
        alert(v1);
        var v2 = f; //将函数体赋值给v2
        v2();
    </script>
</head>
<body>

</body>
</html>

 

posted @ 2013-07-30 15:23  小小一书童  阅读(345)  评论(0编辑  收藏  举报