[英]what's the difference between mon() and on() in extjs?
有谁能解释一下ExtJS中mon()
和on()
之间的区别?
Well, if you want to avoid memory leaks then you use mon instead of on to bind events. 好吧,如果你想避免内存泄漏,那么你使用mon而不是on来绑定事件。 For example:
例如:
var p = new Ext.Panel({
renderTo:Ext.getBody()
,title:'Panel with a listener on the body'
,beforeDestroy:function() {
this.body.un('click', handler);
}
});
If you add listeners as inline function, like: 如果将侦听器添加为内联函数,例如:
p.on('click', function() {alert('You clicked my body')});
then it not possible to remove this listener selectively . 那么就不可能有选择地删除这个监听器。 But, if you use mon for it, then the listener is automatically removed by ExtJs on panel destroy.
但是,如果你使用mon ,那么侦听器会被面板destroy上的ExtJs自动删除。
mon - Adds listeners to any Observable object (or Ext.Element) which are automatically removed when this Component is destroyed. mon - 将侦听器添加到任何Observable对象(或Ext.Element),这些对象在销毁此Component时自动删除。
on - Appends an event handler to an observable object on - 将事件处理程序附加到可观察对象
See: 看到:
http://docs.sencha.com/ext-js/4-2/#!/api/Ext-method-on http://docs.sencha.com/ext-js/4-2/#!/api/Ext-method-on
http://docs.sencha.com/ext-js/4-2/#!/api/Ext.util.Observable-method-mon http://docs.sencha.com/ext-js/4-2/#!/api/Ext.util.Observable-method-mon
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.