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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<%@ 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 type= "application/javascript" >
     //原型的概念:原型对象里的所有属性和方法被所有构造函数实例化出来的对象所共享
//  function Person(){
//     
//  }
//  Person.prototype={
//      constructor:Person,
//      name:'程序员',
//      age:21,
//      friends:['wangwu','zhaoliu'],
//      say:function(){
//          alert(this.friends);
//      }
//  }
     //原型里的属性和方法被所有对象共享
     /*
     var p1=new Person();
     p1.friends.push('lisi');
     p1.say();                        //wangwu,zhaoliu,lisi
     var p2=new Person();
     p2.say();                        //wangwu,zhaoliu,lisi ,p1添加friends,p2也添加了friends
     */
     
     //组合模式:一般使用原型和构造函数
     /*
     function Person1(name,age,friends,job){
         this.name=name;
         this.age=age;
         this.friends=friends;
         this.job=this.job;
         
     }
     Person1.prototype={
         constructor:Person1,
         sayName:function(){
             alert(this.name);
         }
     }
     
     
     var p3=new Person1('zhangsan',21,['wangwu','zhaoliu'],'程序员');
     var p4=new Person1('lisi',21,['wangwu','zhaoliu'],'程序员');
     p3.sayName();
     p4.sayName();
     
     */
     
     
     
     //动态原型模式(让你的代码封装到一起)
     /*
     function Person2(name,age,friends,job){
         this.name=name;
         this.age=age;
         this.friends=friends;
         this.job=this.job;
         //动态原型方法
         if(typeof this.sayName !='function'){
             //
             Person2.prototype.sayName=function(){          //sayName方法只创建一次
                 
                 alert(this.name);
             }
         }
         
     }
     var p5=new Person2('zhangsan',21,['wabgwu','zhaoliu'],'chengxuyuan');
     p5.sayName();
     
     */
     
     //稳妥构造函数式   durable object(稳妥对象) 非常安全的环境中
     //1.没有公共属性,
     //其他对象中也不引用this对象,不能使用this关键字
     function  Person3(name,age,job){
         var  object={};
         //可以定义私有的方法和属性
         var  name=name;
         var  age=23;
         var  job= '程序员' ;
         object.sayName= function (){
             alert(name);
         }
         return  object;
     }
     
     
     var  p7= new  Person3( 'zhangsan' ,21, 'chenuxyuan' );
     p7.sayName();
     
     
     
     </script> 
     
   </head>
   
   <body>
     This is my JSP page. <br>
   </body>
</html>