Person = function(name) {
this.name = name;
this.fn = function() { alert('I am a person') };
}
Person.prototype.print=function(){ alert('I am a person');}
Person.prototype.showAge = function() { alert('I am older than 0'); }
Person.prototype.showName = function() { alert('Show Name:'+this.name) };
var per = new Person('Tom');
per.showName();子类:Student = function(id) {
this.id = id;
}
Student.prototype.showID = function() { alert(this.id); } //子类的方法
var stu = new Student('01');
Student.override({ print: function() { alert('I am a student'); } });
stu.override({ print: function() { alert('I am a bad student,but I won't affect others'); } });
stu.print();
stu.showAge();
var stu2 = new Student();
stu2.print();
// inline overrides
var io = function(o){ //注意这个方法的this,仅看这里并不知道这个this是什么,下面这个io会被赋值给sbp.override,也就是子类的prototype
for(var m in o){ //从而每个子类的对象的override都会指向这个方法,如果子类对象调用了override,那么这个this就是子类的对象了。也就是
this[m] = o[m]; //上面的例子中stu.override表现出来的效果,仅对当前对象有效。从这里可以看出,override不仅仅是传统意义上的覆盖,完全也可以
} //用来添加新方法。
};
var oc = Object.prototype.constructor;
return function(sb, sp, overrides){
if(Ext.isObject(sp)){ //是在检测当前使用的是哪个版本的重构函数。如果sp实际上是overrides,就做些替换工作,让变量的实际意义和名称相符合。
overrides = sp;
sp = sb;
sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);}; //这个没看懂……
}
var F = function(){},
sbp,
spp = sp.prototype;
F.prototype = spp; //F是父类的一个“干净”拷贝,所谓干净,是指它不会把父类中在构造函数内部定义的属性带过来。 //例如 Person=function() // {this.privateFn=new function{ some code goes here}} //那么这个privateFn对子类是不可见的,所以在构造函数中利用this定义的属性都相当于是类的私有变量。
sbp = sb.prototype = new F(); //将子类的prototype设置为父类的prototype,继承的核心步骤。 sbp.constructor=sb; //设置正确的构造函数指向,见 JavaScript继承详解
sb.superclass=spp; //设置父类
if(spp.constructor == oc){ //没看懂……,这个是干嘛用的?望高人指点
spp.constructor=sp;
}
sb.override = function(o){ //子类的重写方法,这个重写方法是函数的重写方法。它修改的是prototype。
Ext.override(sb, o); //见最后。
};
sbp.superclass = sbp.supr = (function(){ //设置原型的父类
return spp;
});
sbp.override = io; //给子类的prototype提供override方法,这样单个实体也可以覆盖,它修改的是实体对象。注意和上面的sb的override区分。
Ext.override(sb, overrides); //重写
sb.extend = function(o){return Ext.extend(sb, o);}; //给子类提供extend方法,以实现多重继承
return sb; //返回子类。
};
}();
function(origclass, overrides){
if(overrides){
var p = origclass.prototype;
Ext.apply(p, overrides);
if(Ext.isIE && overrides.hasOwnProperty('toString')){ // 这个是什么?IE的特殊点?
p.toString = overrides.toString;
}
}
}
Odder = function(min, max) {
this.min = min;
this.max = max;
this.addEvents('onFindOdd');
}
Ext.extend(Odder, Ext.util.Observable, { run:
function() {
for (var i = this.min; i < this.max; i++) {
if (i % 2 != 0) {
this.fireEvent('onFindOdd',i);
}
}
}
});
var p = new Odder(4, 8);
p.addListener('onFindOdd',function(n){alert(n);});
p.run();
Employee = Ext.extend(Ext.util.Observable, {
constructor: function(config){
this.name = config.name;
this.addEvents({
"fired" : true,
"quit" : true
});
// Copy configured listeners into *this* object so that the base class's
// constructor will add them.
this.listeners = config.listeners;
// Call our superclass constructor to complete construction process.
Employee.superclass.constructor.call(config)
}
});This could then be used like this:
var newEmployee = new Employee({
name: employeeName,
listeners: {
quit: function() {
// By default, "this" will be the object that fired the event.
alert(this.name + " has quit!");
}
}
});
Extjs TriggerField在弹出窗口显示不出问题的解决方法
一、原因分析this.WinData.AutoLoad.Mode=LoadMode.IFrame;WinData.AnimateTarget="BtnEdit";PHWin.Controls.Add(WinData);使用PlaceHolder让窗口弹出具有动画效果二、解决方案this.WinDat
Extjs学习笔记之九 数据模型(上)
Extjs的数据模型分为以下几个部分:数据记录Record数据集合中的一个条记录,包括数据的定义和值。相当于实体类。数据代理Proxy用来获取数据的代理。
extjs 为某个事件设置拦截器
我们先来自定义一个事件:person=function(name){this.name=name;this.addEvents("walk");}Ext.extend(person,Ext.util.Observable,{info:function(event){returnthis.name+'is'+event+'ing.';}});varpe