1:支持命名空间
1
2
3
4
5
6
7
8
9
|
<script type= "text/javascript" >
//定义一个命名空间
Ext.namespace( "Ext.baojian" );
//在命名空间上定义一个类
Ext.baojian.helloworld = Ext.emptyFn;
//创建一个类的实例
new Ext.baojian.helloworld();
</script>
|
2:支持类实例属性
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<script type= "text/javascript" >
Ext.namespace( "Ext.baojian" ); //自定义一个命名空间
Ext.baojian.Person = Ext.emptyFn; //在命名空间上自定义一个类
//为自定义的类 增加一个 name 属性,并赋值
Ext.apply(Ext.baojian.Person.prototype, {
name: "王宝健"
})
var _person = new Ext.baojian.Person(); //实例化 自定义类
alert(_person.name);
_person.name = "杨波" ; //修改类name属性
alert(_person.name);
</script>
|
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<script type= "text/javascript" >
Ext.namespace( "Ext.baojian" ); //自定义一个命名空间
Ext.baojian.Person = Ext.emptyFn; //在命名空间上自定义一个类
//演示类实例方法
Ext.apply(Ext.baojian.Person.prototype, {
name: "王宝健" ,
sex: "男" ,
print: function (){
alert(String.format( "姓名:{0},性别:{1}" , this .name, this .sex));
}
})
var _person = new Ext.baojian.Person(); //实例化 自定义类
_person.print();
</script>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<script type= "text/javascript" >
Ext.namespace( "Ext.baojian" ); //自定义一个命名空间
Ext.baojian.Person = Ext.emptyFn; //在命名空间上自定义一个类
//演示类实例方法
Ext.apply(Ext.baojian.Person.prototype, {
name: "王宝健" ,
sex: "男" ,
print: function (){
alert(String.format( "姓名:{0},性别:{1}" , this .name, this .sex));
}
})
//演示 类静态方法
Ext.baojian.Person.print = function (_name,_sex){
var _person = new Ext.baojian.Person();
_person.name = _name;
_person.sex = _sex;
_person.print(); //此处调用类 实例方法,上面print是类 静态方法
}
Ext.wentao.Person.print( "杨波" , "女" ); //调用类 静态方法
</script>
|
5:支持构造方法
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<script type= "text/javascript" >
Ext.namespace( "Ext.wentao" ); //自定义一个命名空间
//构造方法
Ext.baojian.Person = function (_cfg){
Ext.apply( this ,_cfg);
}
//演示类实例方法
Ext.apply(Ext.baojian.Person.prototype, {
print: function (){
alert(String.format( "姓名:{0},性别:{1}" , this .name, this .sex));
}
})
//演示 类静态方法
Ext.baojian.Person.print = function (_name,_sex){
var _person = new Ext.baojian.Person({name:_name,sex:_sex});
_person.print(); //此处调用类 实例方法,上面print是类 静态方法
}
Ext.baojian.Person.print( "杨波" , "女" ); //调用类 静态方法
</script>
|
6:支持类继承
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
|
<script type= "text/javascript" >
Ext.namespace( "Ext.baojian" ); //自定义一个命名空间
//*******************父类*********************
//构造方法
Ext.wentao.Person = function (_cfg){
Ext.apply( this ,_cfg);
}
//演示类实例方法
Ext.apply(Ext.baojian.Person.prototype, {
job: "无" ,
print: function (){
alert(String.format( "姓名:{0},性别:{1},角色:{2}" , this .name, this .sex, this .job));
}
})
//*******************子类1*********************
Ext.baojian.Student = function (_cfg){
Ext.apply( this ,_cfg);
}
Ext.extend(Ext.baojian.Student,Ext.baojian.Person,{
job: "上班族"
})
var _student = new Ext.baojian.Student({name: "杨波" ,sex: "女" });
_student.print(); //调用 父类方法
</script>
|
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
|
<script type= "text/javascript" >
Ext.namespace( "Ext.baojian" ); //自定义一个命名空间
//*******************父类*********************
//构造方法
Ext.wentao.Person = function (_cfg){
Ext.apply( this ,_cfg);
}
//演示类实例方法
Ext.apply(Ext.baojian.Person.prototype, {
job: "无" ,
print: function (){
alert(String.format( "姓名:{0},性别:{1},角色:{2}" , this .name, this .sex, this .job));
}
})
//*******************子类1*********************
Ext.wentao.Student = function (_cfg){
Ext.apply( this ,_cfg);
}
//重写父类的 实例 方法
Ext.extend(Ext.baojian.Student,Ext.baojian.Person,{
job: "上班族" ,
print: function (){
alert(String.format( "{0}是一位{1}{2}" , this .name, this .sex, this .job));
}
})
var _student = new Ext.baojian.Student({name: "杨波" ,sex: "女" });
_student.print(); //调用 父类方法
</script>
|
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
|
<script type= "text/javascript" >
Ext.namespace( "Ext.baojian" ); //自定义一个命名空间
Bj = Ext.wentao; //命名空间的别名
//*******************父类*********************
//构造方法
Wt.Person = function (_cfg){
Ext.apply( this ,_cfg);
}
//演示类实例方法
Ext.apply(Bj.Person.prototype, {
job: "无" ,
print: function (){
alert(String.format( "姓名:{0},性别:{1},角色:{2}" , this .name, this .sex, this .job));
}
})
//*******************子类1*********************
Wt.Student = function (_cfg){
Ext.apply( this ,_cfg);
}
//重写父类的 实例 方法
Ext.extend(Bj.Student,Ext.baojian.Person,{
job: "学生" ,
print: function (){
alert(String.format( "{0}是一位{1}{2}" , this .name, this .sex, this .job));
}
})
var _student = new Bj.Student({name: "杨波" ,sex: "女" });
_student.print(); //调用 父类方法
</script>
|
?
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
|
<script type= "text/javascript" >
Ext.namespace( "Ext.baojian" ); //自定义一个命名空间
Bj = Ext.baojian; //命名空间的别名
//*******************父类*********************
//构造方法
Bj.Person = function (_cfg){
Ext.apply( this ,_cfg);
}
PN = Bj.Person; //类别名
//演示类实例方法
Ext.apply(PN.prototype, {
job: "无" ,
print: function (){
alert(String.format( "姓名:{0},性别:{1},角色:{2}" , this .name, this .sex, this .job));
}
})
//*******************子类1*********************
Bj.Student = function (_cfg){
Ext.apply( this ,_cfg);
}
ST = Bj.Student;
//重写父类的 实例 方法
Ext.extend(ST,PN,{
job: "上班族" ,
print: function (){
alert(String.format( "{0}是一位{1}{2}" , this .name, this .sex, this .job));
}
})
var _student = new ST({name: "杨波" ,sex: "女" });
_student.print(); //调用 父类方法
</script>
|