|
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
|
<%@ 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>
//原型prototype
//构造函数式 每个对象都有属性和sayname函数
// function Person(name,age){
// this.name=name;
// this.age=age;
// this.sayname=function(){
// return this.name;
// }
// }
// function sayName(){
// return this.name;
// }
// var p1=new Person('zhangsan','男');
// var p2=new Person('wangwu','女');
// //alert(p1.sayname()==p2.sayname()); //false
// //alert(p1.name==p2.name); //false
// alert(p1.sayname());
// alert(p2.sayname());
/*
function Person(name,age){
this.name=name;
this.age=age;
this.sayname=sayName;
}
function sayName(){
alert(this.name);
}
var p1=new Person('zhangsan','男');
var p2=new Person('wangwu','女');
alert(p1.sayname()==p2.sayname()); //true
//alert(p1.sayname());
//alert(p2.sayname());
*/
//创建每一个函数都有一个prototype属性,这个属性其实是指针,这个指针总是指向一个对象
// 这个对象用途是将特定的属性和方法包含在内,起到一个所有对象共享的作用
//原型对象 每个对象共享属性和对象
function
Person(){
}
var
obj=Person.prototype;
obj.name=
'张三'
;
obj.age=23;
obj.sayName=
function
(){alert(
this
.name);}
var
p1=
new
Person();
var
p2=
new
Person();
//alert(p1.age);
//alert(p2.age);
//p1.sayName();
//p2.sayName();
alert(p1.sayName()==p2.sayName());
//构造函数.prototype=原型对象
//原型对象.constructor=构造函数
alert(obj.constructor);
//实例对象.prototype=原型对象
alert(obj.isPrototypeOf(p1));
//true obj是p1的原型
</script>
</head>
<body>
This is my JSP page. <br>
</body>
</html>
|
本文转自 matengbing 51CTO博客,原文链接:http://blog.51cto.com/matengbing/1879237
