What the hell is mon and mun?
2011-10-15 11:44
323 查看
What the hell is mon and mun?
18. September 2009 – 02:31I’ve run across the following code in some of Ext 3.x examples:
this.mon(toolsUl, 'click', this.onClick, this);
Looks like event handler installation but what it really does anyway?
So I delved into the code and remembered ExtJS Conference and now it is clear to me.
Imagine you create a component and then you need to install an event handler, for example, on its body. Something like:
var handler = function() { alert('You clicked my body'); }; var p = new Ext.Panel({ renderTo:Ext.getBody() ,title:'Panel with a listener on the body' }); p.body.on('click', handler);
Easy enough, we’ve done something like this many times. But, if the panel is ever to be destroyed we need to remove this listener ourselves as Ext knows nothing about it.
Something like:
var p = new Ext.Panel({ renderTo:Ext.getBody() ,title:'Panel with a listener on the body' ,beforeDestroy:function() { this.body.un('click', handler); } });
If we install our listener as inline function, such as:
p.on('click', function() {alert('You clicked my body')});
then it is impossible to remove this listener selectively, you would need to use
p.body.removeAllListeners();
to remove all body listeners.
Now, if we use
mon(m stands for “managed”) this way
p.mon(p.body, 'click', handler);
then the listener is automatically removed by Ext on panel destroy. Nice, isn’t it? Saves a lot of our work and also handles our laziness or forgetfulness about destroying and cleanups of components.
Mind the first argument, that is the element to install the listener to. It can, but not necessarily have to be within the component. Also remember that when you destroy
pExt only removes listener from the element so if the element is outside
of
pyou need to remove it yourself if it is not necessary anymore.
Should you ever need to remove the listener installed by
monyou use
munwith same arguments. You cannot selectively remove inline listeners.
monand
munare defined in Component so you can use them from Component down the descendant classes chain.
相关文章推荐
- What in the hell is the AP and mAP?
- what is the hell of uv's tiling and offset
- What is the PPA and How to do with it ?
- What is the difference between Binding and TemplateBinding?
- What exactly is copy-on-modify semantics in R, and where is the canonical source?
- What exactly is the difference between WndProc and DefaultWndProc?
- What is the difference between objectForKey and valueForKey?
- What is the difference between char s[] and char *s?
- What is the difference between SET and SELECT when assigning values to variables, in T-SQL?
- usb驱动---What is the difference between /dev/ttyUSB and /dev/ttyACM【转】
- what the hell it is?!
- Whats is the difference between train, validation and test set, in neural networks?
- What is the difference between extensibility and scalability?
- What is the difference between WM_DESTROY and WM_NCDESTROY?
- macro与inline的区别 What is the difference between macro and inline?
- What is the difference between a Bayesian network and a Naive Bayes classifier?
- What is the difference between the Linux Kernel and the Android Kernel?
- what is the difference between _source and _all in Elasticsearch
- What is the difference between a Session and a Cookie?
- What is the difference between ContentPresenter and ContentControl?