ext mon과 on의 차이
1. on 방법은 실제addListener의 약자로 Ext.util에 있다.Observable에 정의된 역할은
"Appends an event handler to this object.",즉 현재 대상에 이벤트 처리 함수를 추가하는 것이다
코드는 아래와 같다(잘 이해하지 못하다)는 귀속 함수이다
addListener : function(eventName, fn, scope, o){
var me = this,
e,
oe,
isF,
ce;
if (ISOBJECT(eventName)) {
o = eventName;
for (e in o){
oe = o[e];
if (!filterOptRe.test(e)) {
me.addListener(e, oe.fn || oe, oe.scope || o.scope, oe.fn ? oe : o);
}
}
} else {
eventName = toLower(eventName);
ce = me.events[eventName] || TRUE;
if (typeof ce == "boolean") {
me.events[eventName] = ce = new EXTUTIL.Event(me, eventName);
}
ce.addListener(fn, scope, ISOBJECT(o) ? o : {});
}
},
2.mon 방법은 Ext3에서 메모리 유출 문제를 해결하기 위해 (무슨 문제인지 모르면 일부 핸들이 자동으로 삭제되지 않을 수도 있음) 개선한 것으로Component류에 정의되어 현재 대상에 외부 대상에 추가된 이벤트 핸들이 현재 대상이 삭제될 때 자동으로 핸들을 제거합니다.코드는 다음과 같습니다.
mon : function(item, ename, fn, scope, opt){
if(!this.mons){
this.mons = [];
this.on('beforedestroy', this.clearMons, this, {single: true});
}
if(Ext.isObject(ename)){
var propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
var o = ename;
for(var e in o){
if(propRe.test(e)){
continue;
}
if(Ext.isFunction(o[e])){
// shared options
this.mons.push({
item: item, ename: e, fn: o[e], scope: o.scope
});
item.on(e, o[e], o.scope, o);
}else{
// individual options
this.mons.push({
item: item, ename: e, fn: o[e], scope: o.scope
});
item.on(e, o[e]);
}
}
return;
}
this.mons.push({
item: item, ename: ename, fn: fn, scope: scope
});
item.on(ename, fn, scope, opt);
},
코드에서 현재 대상이 템플릿 방법인 beforedestroy에서 자동으로 핸들 정리 작업을 진행하여 메모리 유출을 줄이는 것을 똑똑히 볼 수 있다.
Ext 공식적으로 모든 componet 클래스에 핸들을 추가할 때 몬 대체 on을 사용하도록 추천합니다
인용하다
//Old Style
this.el.on('click', this.onClick, this);
//New Style
this.mon(this.el, 'click', this.onClick, this);
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
개인 FLEX 지식 라이브러리 작업 노트[size=large]1、 이 방법은 TileWindows 팝업 창에 있습니다. TitleWindows의 maxWidth와 maxHeight를 지정하지 않으면 최대 값이 화면 전체에 깔립니다. 페이지의minHeigh...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.