我是靠谱客的博主 冷傲凉面,这篇文章主要介绍为什么let this=that,现在分享给大家,希望可以做个参考。

复制代码
1
不知道大家有没有接触过jquery jquery里边有一个特别典型的例子能说明用_this的作用
复制代码
1
2
3
4
5
6
7
$("#btn").click(function(){ var that = this;//这里this和that都代表了"#btn"这个对象 $(".tr").each(function(){ this;//在这里this代表的是每个遍历到的".tr"对象 that;//仍代表"#btn"对象 }) })
复制代码
1
这种情况就是在一个代码片段里this有可能代表不同的对象,而编码者希望_this代表最初的对象
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
let that = this; var ajax = new XMLHttpRequest(); ajax.open('get','http://127.0.0.1:24010/ZKIDROnline/ScanReadIdCardInfo?OP-DEV=1&CMD-URL=4'); ajax.send(); ajax.onreadystatechange = function () { if (ajax.readyState===4 &&ajax.status===200) { /*eslint-disable no-eval */ //这个注释必须要 var data = eval("(" + ajax.responseText + ")"); let res = data.Certificate; if (res) { that.setState({ value: res }) }   } }

 

最后

以上就是冷傲凉面最近收集整理的关于为什么let this=that的全部内容,更多相关为什么let内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部