您的位置:首页 > Web前端 > JavaScript

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: