DojoChina之方法重写学习

Ext.namespace('Ext.xredman');

Ext.xredman.Person = function(_cfg){
	Ext.apply(this, _cfg);
};

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

////////////Student,继承时必须写这段,有点怪哇
Ext.xredman.Student = function(_cfg){
	Ext.apply(this, _cfg);
}
//Ext.xredman.Student = Ext.emptyFn;
//在这里重写了print方法
Ext.extend(Ext.xredman.Student, Ext.xredman.Person,{print:function(){
	alert(String.format('Student 姓名:{0},性别:{1}',this.name, this.sex));
}});

//sample
var _person = new Ext.xredman.Person({name:'xredman',sex:'男'});
//_person.print();
var _student =new Ext.xredman.Student({name:'sxredman',sex:'s男'});
_student.print();

 定义:子类在继承父类时对其一见存在的方法进行重写定义。

 

 

Example

 

你可能感兴趣的:(ext,prototype)