var me = this的价值是多少? [英] What is the value of var me = this;
本文介绍了var me = this的价值是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在ExtJS源代码中找到这种模式。
I find this pattern all over the ExtJS source code.
method: function() {
var me = this;
...
me.someOtherMethod();
}
为什么他们不使用 code>?经常定义
我
(不需要输入2个字符),有始终有什么优势吗?我可以理解,如果他们试图通过关闭来维护上下文,但是在没有关闭的地方完成。
Why don't they just use this
? Is there some advantage to always often defining me
(outside of not having to type 2 characters)? I can understand if they are trying to maintain the context via closure, but it's done in places where there is no closure at all.
Ext.panel.Panel的一个例子:
An example from Ext.panel.Panel:
disable: function(silent) {
var me = this;
if (me.rendered) {
me.el.addCls(me.disabledCls);
me.el.dom.disabled = true;
me.onDisable();
}
me.disabled = true;
if (silent !== true) {
me.fireEvent('disable', me);
}
return me;
},
推荐答案
我
可以比这个
短得多。
这篇关于var me = this的价值是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文