1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
     
    <title>My JSP 'test3.jsp' starting page</title>
     
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <script src="js/jquery-2.1.1.min.js"></script>
    <script>
//        function test(a,b){
//            return a+b;
//        }
//        //alert(typeof test);        //函数也是一种数据类型 function类型
//        function test2(aa){
//            aa();
//        }
//        function test3(){
//            alert('test3');
//        }
//        //test2(test3);                 //函数可以当做数据传入,还可以传入匿名函数
//        test2(function(){
//            alert('匿名函数');
//        });
//        //在js函数中是可以嵌套的,避免这样使用
//        function test4(){
//            function test5(){
//                alert('test5');
//            }
//            test5();               //test5的作用域是在test4内部,外部不能直接访问,在test4中调用
//        }
//        //test4();
 
 
 
        //js函数三种定义方式
        //1.function语句式
        function test(){
             
        }
        //2.函数的直接量
        var te=function test2(){
             
        }
         
        //3.function构造函数式
        var test3=new Function('a','b','return a+b');
        //alert(test3(1,2));
         
        //解析顺序问题,对于function语句式的函数,javascript会优先解释
    //    test4();
        function test4(){
            alert('test4');
        }
        //alert(test());                     //undefined  
        //test();                             //无作用,执行test()函数时,还没有执行到test5()函数处(只是有申明而已),所以未定义,表示申明了但是未赋值
        var test=function test5(){
            //alert('test5');
        }
         
        var t1=1;
        function t2(){
            var t1=2;
            //function test(){return t1;}            //2
            //var test=function(){return t1;}       //2
            var test=new Function('return t1');   //构造函数方式式,具有顶级作用域,和卸载外面一样,会输出1
            alert(test());
        }
        t2();
    </script>
  </head>
   
  <body>
    This is my JSP page. <br>
  </body>
</html>