<%@ 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,
say:function(){
alert(‘原型函数‘);
}
};
//ECMA5给原型重新定义构造器的方法 Object.defineProperty()
var p1=new Person();
//alert(p1.name);
p1.say();
//三个参数:1.重设构造器的对象,2.设置什么属性,3.options配置项
Object.defineProperty(Person.prototype,‘constructor‘,{
enumerable:false,
value:Person
});
//alert(Person.prototype.constructor);
function Person1(){
}
var p4=new Person1();
Person1.prototype.say=function(){alert(‘我是Person1的say函数‘);}
p4.say(); //有结果
function Person3(){
}
Person3.prototype={
constructor:Person3,
say:function(){alert(‘我是Person2的say函数‘);}
};
var p6=new Person3();
p6.say(); //有结果
function Person2(){
}
var p5=new Person2();
Person2.prototype={
constructor:Person2,
say:function(){alert(‘我是Person2的say函数‘);}
};
p5.say(); //无结果 error因为原型对象中没有任何方法
//注意简单原型的使用顺序,实例对象必须在原型对象之后
</script>
</head>
<body>
This is my JSP page. <br>
</body>
</html>本文出自 “matengbing” 博客,请务必保留此出处http://matengbing.blog.51cto.com/11395502/1879395
原文:http://matengbing.blog.51cto.com/11395502/1879395