关闭

extjs面向对象二

202人阅读 评论(0) 收藏 举报

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../lib/ext-all.css" />
	<script type="text/javascript" src="../lib/ext-base.js"></script>
    <script type="text/javascript" src="../lib/ext-all.js"></script>
	<script type="text/javascript" src="helloword.js"></script>
</head>
<script type="text/javascript">
Ext.namespace("hb.com");

hb.com.Person = function(cfg){
	Ext.apply(this,cfg);
};

Ext.apply(hb.com.Person.prototype,{
	job:"无",
	print:function(){
		alert(String.format("姓名:{0},性别:{1},工作:{2}",this.name,this.sex,this.job));
	}
});

hb.com.Student = function(cfg){
	Ext.apply(this,cfg);
}

//通过继承的方式覆盖原来属性和方法,达到重写的目的
//这里已经定义好了Person的属性和方法
Ext.extend(hb.com.Student,hb.com.Person,{
	job:"学生",
	print:function(){
		alert(String.format("{0}是做{1}工作的一位{2}性:",this.name,this.job,this.sex));
	}
});
//cfg为Student的初始化数据
var cfg = {name:"huangbiao",sex:"boy"};

var student = new hb.com.Student(cfg);
student.print();
</script>
<body>
    <h1></h1>
    
</body>
</html>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../lib/ext-all.css" />
	<script type="text/javascript" src="../lib/ext-base.js"></script>
    <script type="text/javascript" src="../lib/ext-all.js"></script>
	<script type="text/javascript" src="helloword.js"></script>
</head>
<script type="text/javascript">
Ext.namespace("hb.com");
//给命名空间取别名,命名空间别名首字母大写
Namespace = hb.com;

//使用构造方法的核心
hb.com.Person = function(cfg){
	Ext.apply(this,cfg);
};

Ext.apply(hb.com.Person.prototype,{
	print:function(){
		alert(String.format("姓名:{0},性别:{1}",this.name,this.sex));
	}
});

hb.com.Person.print = function(_name,_sex){
	var person = new hb.com.Person({name:_name,sex:_sex});
	person.print();
}

//这里使用了命名空间别名的方法
Namespace.Person.print("刘梅","女");
</script>
<body>
    <h1></h1>
    
</body>
</html>
 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../lib/ext-all.css" />
	<script type="text/javascript" src="../lib/ext-base.js"></script>
    <script type="text/javascript" src="../lib/ext-all.js"></script>
	<script type="text/javascript" src="helloword.js"></script>
</head>
<script type="text/javascript">
Ext.namespace("hb.com");
//给命名空间取别名,命名空间别名首字母大写
Namespace = hb.com;

//使用构造方法的核心
hb.com.Person = function(cfg){
	Ext.apply(this,cfg);
};

//类使用别名的方法是字母全部大写
PERSON = hb.com.Person ;

Ext.apply(hb.com.Person.prototype,{
	print:function(){
		alert(String.format("姓名:{0},性别:{1}",this.name,this.sex));
	}
});

hb.com.Person.print = function(_name,_sex){
	var person = new hb.com.Person({name:_name,sex:_sex});
	person.print();
}

//这里使用了类的别名
PERSON.print("刘梅","女");
</script>
<body>
    <h1></h1>
    
</body>
</html>
 

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:282402次
    • 积分:8455
    • 等级:
    • 排名:第2300名
    • 原创:1096篇
    • 转载:14篇
    • 译文:0篇
    • 评论:4条
    最新评论