Person类是父类:
1 Ext.namespace("Ext.dojochina");
2 //EXT的构造方法
3 Ext.dojochina.Person = function(_cfg) {
4 Ext.apply(this, _cfg);
5 };
6
7 //实例方法
8 Ext.apply(Ext.dojochina.Person.prototype, {
9 job:"无",
10 print:function(){
11 alert(String.format("姓名:{0}, 性别:{1},角色:{2}", this.name, this.sex, this.job));
12 }
13 });
Student类是继承自Person类的,只是job=Student
1 Ext.namespace("Ext.dojochina");
2 //构造函数
3 Ext.dojochina.Student = function(_cfg) {
4 Ext.apply(this, _cfg);
5 };
6 //继承的写法
7 Ext.extend(Ext.dojochina.Student,Ext.dojochina.Person,{
8 job:"学生"
9 });
JSP页面上的显示:
1 <%@ page language="java" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
2
3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <html>
5 <head>
6
7 <title>Student类Teacher类 继承自Person类</title>
8
9 <link rel="stylesheet" type="text/css" href="./scripts/ext/resources/css/ext-all.css">
10 <script type="text/javascript" src="./scripts/ext/adapter/ext/ext-base.js"></script>
11 <script type="text/javascript" src="./scripts/ext/ext-all.js"></script>
12 <!--注意上面两个JS文件的导入顺序 -->
13 <script type="text/javascript" src="./scripts/ext/demo/Person.js"></script>
14 <script type="text/javascript" src="./scripts/ext/demo/Student.js"></script>
15 <script type="text/javascript" src="./scripts/ext/demo/Teacher.js"></script>
16
17 <script type="text/javascript">
18 var _teacher = new Ext.dojochina.Teacher({name:"老杨",sex:"Man"});
19 _teacher.print();
20 var _student = new Ext.dojochina.Student({name:"Lily", sex:"Woman"});
21 _student.print();
22 </script>
23
24 </head>
25
26 <body>
27 测试类的继承 <br>
28 ---] Student类Teacher类 继承于Person类
29 </body>
30 </html>
31
32