extjs中为什么使用“var me = this”?
2012-06-18 10:42
274 查看
在ExtJs例子里看到大量“var me = this”,上网找了下,在:http://www.sencha.com/forum/showthread.php?136318-Why-use-quot-var-me-this-quot 找到答案:
Say you have a method in your object A which itself makes an ajax request which has a callback. In this callback you want to use a property "blob" of your original object A. You can not use "this.blob" in this callback because "this" does not refer to your object A anymore (Your scope is in the ajax request). For this reason you save "this" to a variable "me" before you call the function and then refer to "me.blob" to reference the porperty A.blob.
就是说当你用到回调函数的时候是无法使用this的,所以要先用me来保存this指针。
引用:http://hi.baidu.com/antzhi/item/8f5c634dd9a221eda5c06608
Say you have a method in your object A which itself makes an ajax request which has a callback. In this callback you want to use a property "blob" of your original object A. You can not use "this.blob" in this callback because "this" does not refer to your object A anymore (Your scope is in the ajax request). For this reason you save "this" to a variable "me" before you call the function and then refer to "me.blob" to reference the porperty A.blob.
就是说当你用到回调函数的时候是无法使用this的,所以要先用me来保存this指针。
引用:http://hi.baidu.com/antzhi/item/8f5c634dd9a221eda5c06608
相关文章推荐
- 为什么要使用“var me=this”这样的写法
- 为什么要使用“var me=this”这样的写法
- 为什么要使用“var me=this”这样的写法
- 为什么要使用“var me=this”这样的写法
- ExtJs4组件中initComponent方法介绍以及为什么要使用this.callParent();
- 为什么静态方法中不能使用this和super关键字
- java中静态方法中为什么不能使用this、super和直接调用非静态方法
- 为什么要写var that = this;
- javascript中,一个js中的函数,第一句var _this = this;为什么要这样做?
- 为什么很多【JQuery】代码里会在开头加个var _this = this;
- 静态方法中为什么不能使用super和this
- 使用ActionBar,调整Theme时遇到You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- 静态方法中为什么不能使用this
- 为什么使用enable_shared_from_this——shared_ptr两类错误
- 使用AlertDialog报错 You need to use a Theme.AppCompat theme (or descendant) with this activity.之解决
- js中,一个js中的函数,第一句var thiz = this; 为什么要这样做?
- 静态方法为什么不能使用this和super关键字
- 为什么在js中要写var this =that?
- Activity使用主题不兼容报错-You need to use a Theme.AppCompat theme (or descendant) with this activity
- extjs designer linux version only have 64-bit version,this embrancy me alot