extjs面向对象设计

Ext.namespace('Ext.practise');

//给person类添加了name属性,并赋值

Ext.apply(Ext.practise.Person.prototype,{

name:'a'

});

//{}表示一个类

//[]表示一个数组

//类的实例方法

Ext.apply(Ext.practise.Person.prototype,{

name:'a',

sex:'b',

print:function(){

alert(String.format("姓名:{0},性别:{1}",this.name,this.sex));

}

});

varperson=newExt.practise.Person();

person.name="a";

person.sex="b";

person.print();

//类的静态方法

Ext.practise.Peron.print=function(_name,_sex){

varperson=newExt.practise.Peron();

person.name=_name;

person.sex=_sex;

person.print();

};

//构造方法

Ext.practise.Peron=function(_cfg){

Ext.apply(this,_cfg);

};

Ext.practise.Peron=function(_name,_sex){

varperson=newExt.practise.Peron({name:_name,sex:_sex});

person.print();

};

Ext.apply(Ext.practise.Peron.prototype,{

print:function(){

alert(String.format("姓名:{0},性别:{1}",this.name,this.sex));

}

});

var p = new Ext.practise.Peron({name : "a",sex:"b"});p.print();

//类继承

Ext.practise.Peron=function(_cfg){//_cfg父类

Ext.apply(this,_cfg);

};

Ext.apply(Ext.practise.Peron.prototype,{

job:"worker",

print:function(){

alert("name:{0},sex:{1},job:{2}",this.name,this.sex,this.job);

}

});

Ext.practise.man = function(_cfg){//子类

Ext.apply(this,_cfg);

};

Ext.extend(Ext.practise.man,Ext.practise.Peron,{job:"teacher"});

//类重写

Ext.extend(Ext.practise.man,Ext.practise.Peron,{

print:function(){

alert("man覆盖了person的方法");

}

});

相关推荐