当前位置:网站首页>This的指向
This的指向
2022-08-06 05:18:00 【Falsify_】
在 js 中 this 不是固定不变的,它会随着执行环境的改变而改变。要注意的是 this 取什么值,是在执行时确认的,定义时无法确认。
this 的调用大概分为四种场景:
1.浏览器里,在全局范围内的 this 指向 window 对象;
2.在函数中,this 永远指向最后调用他的那个对象;
3.构造函数中,this 指向 new 出来的那个新的对象;
4.箭头函数中 this 比较特殊,箭头函数 this 为父作用域的 this,不是调用时的 this.要知道前四种方式,都是调用时确定,也就是动态的,而箭头函数的 this 指向是静态的,声明的时候就确定了下来;
边栏推荐
猜你喜欢
随机推荐
信奥一本通1261:【例9.5】城市交通路网 动态规划
Environmental sensitivity/thermal NMR/auxin-loaded/membrane-loaded/protein-loaded hydrogels
"Still too young, interns take 2 minutes to measure the bug, the reaction of the old tester intriguing
把任意网站变成桌面软件
编辑距离问题(动态规划)的详细易懂讲解
2065:【例2.2】整数的和
Uniapp static file is too large solution
2064:【例2.1】交换值
What is wrong with flinkcdc mysql DataStream API?
Why does Baidu Intelligent Cloud Digital Human lead the Chinese AI Digital Human?
“还是太年轻”,实习生花2分钟测出bug,老测试员的反应耐人寻味
Explanation of the Extra field in the Explain information
Routing - the route
php fails to write data to mysql
数学建模学习(78):多输入多输出回归预测模型(结合XGBoost实现)
VS2010编译执行自定义命令
基于 DDD 的微服务设计和开发实战
双网口配置,无线and有线
Explain信息中Extra字段解释
canvas








