日期:2014-05-16  浏览次数:20370 次

extjs面向对象二

?

<!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>
?

?